jQuery - 如何将对象向左和向右移动

时间:2016-10-04 03:34:07

标签: jquery

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

如何在网站末尾创建像此轮播一样移动对象的效果。

Digital Media

通过单击左(鼠标)并在两侧移动对象来实现手的效果。

/** 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 -->

2 个答案:

答案 0 :(得分:0)

只需使用此jquery插件,感谢owl carousel 2

<强> HTML

<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
        }
    }
})

}

DEMO

答案 1 :(得分:0)

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

或者您可以设置元素的偏移量,以便在拖动鼠标时向左或向右移动。

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

可以找到一个简单的答案here,希望它可以解决更复杂的答案。