限时优惠活动
亲爱的苦力吧用户,我们为了回馈新老用户一直以来的鼎力支持,即日起(2025-02-06至2025-03-06)凡是购买苦力吧VIP/充值K币的新老用户,都直接可获得买一送一的优惠馈赠。例如:购买一个月的VIP会员可直接获得两个月的VIP会员;充值100K币可直接获得200K币,以此类推!有任何疑问可联系在线客服,感谢各位用户对苦力吧素材的信任与厚爱,我们将一如既往的给大家上新更多优质的素材源码,祝大家开工大吉、工作顺利、心想事成。

原生js实现的带平滑动画展开收缩特效代码

所属分类: 网页特效-展开&收缩    2023-11-26 04:31:53

原生js实现的带平滑动画展开收缩特效代码 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

原生js实现的带平滑动画展开收缩特效代码(共3个文件)

    • index.html

使用方法

"use strict";

//we want to get all blockquotes as an array instead of a nodelist
const blockquotes = [].slice.call(document.querySelectorAll('blockquote'));

//do the things we need to to each blockquote on the page
blockquotes.map(blockquote => {
  //we only want an expander to be added if it is taller than 200px
  if(blockquote.clientHeight > 200) {
    //add data-state closed to the blockquote
    blockquote.setAttribute('data-state','closed');
    //create a span that will hold our expand button
    const gradient = document.createElement("span");
    //give it the class .bqe-gradient to add a gradient background
    gradient.classList.add('bqe-gradient');
    
    //create the expander button
    const expander = document.createElement("span");
    //add .bqe-expander class for styling
    expander.classList.add('bqe-expander');
    //add a funky hand pointer
    expander.innerHTML = '☟';  
    //add our expander element into the gradient element and then
    //add the gradient element into the blockquote
    blockquote.appendChild(gradient).appendChild(expander);
  }
});

//get all the .bqe-expander elements as array
const allExpanders = [].slice.call(document.querySelectorAll('.bqe-expander'));
//add event listener to each element so we can toggle the data-state 
allExpanders.map(expander => {expander.addEventListener('click', expandBlockquote)});

function expandBlockquote() {
  //our button is nested in the gradient span
  //so we want the parent of the parent
  const parEl = this.parentElement.parentElement;
  //toggle our data state thanks to:
  //https://toddmotto.com/stop-toggling-classes-with-js-use-behaviour-driven-dom-manipulation-with-data-states/
  parEl.setAttribute('data-state', parEl.getAttribute('data-state') === 'open' ? 'closed' : 'open');
}

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 展开&收缩

jquery展开收缩的查看更多自定义折叠特效代码

一款可自定义显示行数折叠插件,可折叠超过指定行的文本内容,点击“查看更多”可展开显示被隐藏的文本内容。
  展开&收缩
 4325  0

jquery可折叠展开的分支树结构插件

一款支持展开折叠的树结构插件,呈现了一个可折叠和可扩展的树结构,表示各种节点之间的层次关系。
  展开&收缩
 7356  0

jquery垂直展开收缩的手风琴特效代码

一款垂直手风琴特效组件,支持键盘上下箭头控制展开收缩操作,弹性动画呈现展开收缩。
  展开&收缩
 8316  0

jquery鼠标单击或悬停显示隐藏文本内容特效代码

一个功能强大的内容切换插件,通过单击箭头可展开显示隐藏的文本内容,或可以鼠标悬停显示。
  展开&收缩
 5342  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论