jQuery -如何左右移动对象



我很确定这是一个非常非常简单的问题,但即使经过几个小时的阅读Stackoverflow/Google…还是没有运气

如何在网站的末尾创建像这个旋转木马这样的移动物体的效果。

数字媒体

用手点击左键(鼠标的左键)并在两边移动物体的效果

/** page structure **/
#w {
  display: block;
  width: 750px;
  margin: 0 auto;
  padding-top: 30px;
  padding-bottom: 45px;
}
#content {
  display: block;
  width: 100%;
  background: #fff;
  padding: 25px 20px;
  padding-bottom: 35px;
  -webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 1px 2px 0px;
  -moz-box-shadow: rgba(0, 0, 0, 0.1) 0px 1px 2px 0px;
  box-shadow: rgba(0, 0, 0, 0.1) 0px 1px 2px 0px;
}
/** client logos **/
#clients {
  display: block;
  margin-bottom: 15px;
}
#clients .clients-wrap {
  display: block;
  width: 700px;
  margin: 0 auto;
  overflow: hidden;
}
#clients .clients-wrap ul {
  display: block;
  list-style: none;
  position: relative;
}
#clients .clients-wrap ul li {
  display: block;
  float: left;
  position: relative;
  width: 140px;
  height: 55px;
  line-height: 55px;
  text-align: center;
}
#clients .clients-wrap ul li img {
  vertical-align: middle;
  max-width: 100%;
  max-height: 100%;
  -webkit-transition: all 0.3s linear;
  -moz-transition: all 0.3s linear;
  transition: all 0.3s linear;
  -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=65)";
  filter: alpha(opacity=65); 
  opacity: 0.65;
}
#clients .clients-wrap ul li img:hover {
  -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
  filter: alpha(opacity=100); 
  opacity: 1.0;
}
<div id="w">
  <div id="content">
    <div id="clients">
      <h3>Past &amp; Present Clients</h3>
      <div class="clients-wrap">
        <ul id="clients-list" class="clearfix">
          <li><img src="http://wp1.themexlab.com/html/digital-media/img/resources/c-1.png" alt="Cartoon Network"></li>
          <li><img src="http://wp1.themexlab.com/html/digital-media/img/resources/c-2.png" alt="Rough Draft Studios"></li>
          <li><img src="http://wp1.themexlab.com/html/digital-media/img/resources/c-3.png" alt="SpongeBob Movie #2"></li>
          <li><img src="http://wp1.themexlab.com/html/digital-media/img/resources/c-4.png" alt="Apple Computers"></li>
          <li><img src="http://wp1.themexlab.com/html/digital-media/img/resources/c-5.png" alt="Google chat talk"></li>
          <li><img src="http://wp1.themexlab.com/html/digital-media/img/resources/c-6.png" alt="G4TV channel"></li>
          <li><img src="http://wp1.themexlab.com/html/digital-media/img/resources/c-3.png" alt="Wonka Chocolates and Candy"></li>
        </ul>
      </div><!-- @end .clients-wrap -->
    </div><!-- @end #clients -->
  </div><!-- @end #content -->
</div><!-- @end #w -->

您可以使用jquery .animate()来移动对象。请看这里

也可以设置元素的偏移量,使其在鼠标拖动时向左或向右移动。

$element.offset({left: e.pageX - w/2});

一个简单的答案可以在这里找到,希望它可以解决更复杂的问题,如果你有任何

使用owl carousel 2的jquery插件

<div id="owl-example" class="owl-carousel">
<div>
<img src="http://wp1.themexlab.com/html/digital-media/img/resources/c-1.png">
</div>
<div>
<img src="http://wp1.themexlab.com/html/digital-media/img/resources/c-1.png">
</div>
<div>
<img src="http://wp1.themexlab.com/html/digital-media/img/resources/c-1.png">
</div>
<div>
<img src="http://wp1.themexlab.com/html/digital-media/img/resources/c-1.png">
</div>
<div>
<img src="http://wp1.themexlab.com/html/digital-media/img/resources/c-1.png">
</div>
<div>
<img src="http://wp1.themexlab.com/html/digital-media/img/resources/c-1.png">
</div>
</div>
JQUERY

$(function(){
owl();
})

function owl(){
$('#owl-example').owlCarousel({
    loop:true,
    responsive:{
        0:{
            items:1
        },
        600:{
            items:3
        },
        1000:{
            items:5
        }
    }
})
}
演示

最新更新