【问题标题】:how do i change the js slider effect to fade when my window width is less than 800px?当我的窗口宽度小于 800 像素时,如何将 js 滑块效果更改为淡出?
【发布时间】:2013-10-28 20:21:45
【问题描述】:

我正在寻找一种方法,以便当我的浏览器窗口小于 800 像素时,我的 js 滑块将其效果从(现在正常)更改为淡出。有人可以帮忙吗?

     <ul class="slider">

      <li><img src="images/1" alt="img" width="979" height="470"></li>
      <li><img src="images/2" alt="img" width="979" height="470"></li>
      <li><img src="images/3" alt="img" width="979" height="470"></li>

    </ul>

        $('.slider').bxSlider({
    navigation : true, 
        slideSpeed : 300,
        paginationSpeed : 400,  
        singleItem:true,

    });

【问题讨论】:

  • 你试过什么?使用$(window).width() 获取宽度并检查其是否低于 800
  • 当我的宽度小于 800 像素时,我希望它看起来像这样: $('.slider').bxSlider({ navigation : true, // 显示下一个和上一个按钮 slideSpeed : 300, paginationSpeed : 400, singleItem:true, mode:'fade' });
  • 使用var mode = $(window).width() &gt; 800 ? 'default' : 'fade',然后在mode中使用

标签: javascript jquery html css device-width


【解决方案1】:

您可以滚动自己的脚本来监听调整大小事件,然后检测窗口是否小于 800 像素宽,但我会亲自查看 enquire.js 来解决这个特殊问题。使用 enquire.js,您的解决方案可以很简单。

enquire.register("screen and (max-width:800px)", {

// OPTIONAL
// If supplied, triggered when a media query matches.
match : function() {

   //Code goes in here to change your slider to fade

},      

// OPTIONAL
// If supplied, triggered when the media query transitions 
// *from a matched state to an unmatched state*.
unmatch : function() {}

    //Code goes in here to set your slider transition type to normal

});

希望对您有所帮助。查询对我来说是一个很棒的工具!

【讨论】:

    猜你喜欢
    • 2020-01-17
    • 2018-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-21
    • 2018-09-10
    • 2012-05-25
    相关资源
    最近更新 更多