滚动
window.scroll(x, y)
窗口文档显示区左上角显示的文档的 x、y 坐标(屏幕左上角定位到指定坐标),不能设置滚动时间,必须是两个参数
window.scroll(0, 0) //X轴到最左,y轴到最上
window.scroll(0, $(window).scrollTop()) //只滚动X轴到最左
window.scroll($(window).scrollLeft(), 0) //只滚动y轴到最上
$(dom).scrollTop(滚动高度)
$("div").scrollTop(300) div内的y轴滚动条向下滚300,只有div中的内容超出div高度并且设置了高度超出后出现滚动条时,这个操作才有意义
$(window).scrollTop(100) 窗口y轴滚动条向下滚300
$(dom).scrollLeft(value)和它类似
$(dom).animate({},time)
只能是dom,不能是window\document
$('html,body').animate({scrollTop:0}, 1000); //窗口平滑滚到顶
https://www.jquery123.com/
css3过度、动画
http://www.w3school.com.cn/css3/css3_transition.asp
手写js实现过度、动画
var timer = setInterval(function () {
//动作
left = left + 10
width = width * 0.8
if (left == 0) clearInterval(timer);
}, 10);
轮播swiper
适合首页焦点图、商品页商品主图轮换
http://idangero.us/swiper/
https://github.com/nolimits4web/swiper
new Swiper('#homeSlide', {
loop: true,
autoplay: {
disableOnInteraction: false,
delay:5000
},
pagination: {
el: '.control-nav',
clickable: false
},
on:{
click(){
self.navigateToCommon(self.playPicList[this.realIndex])
}
}
});
横向/纵向better-scroll
适合分类导航超出宽度手动可滚动(需要计算宽度)
也适合纵向内容超出自动出滚动条(不需要计算高度),它可以实现上拉刷新、下拉加载、滑动到指定位置、底部反弹等效果,如果不要求这些效果,纵向滚动可以不使用JS插件。
http://ustbhuangyi.github.io/better-scroll/doc/
var $nav = $("#bbsContentScroll");
var width = 0;
$nav.find("ul li").each(function(){
width += $(this).outerWidth(true);
});
$nav.find("ul").css("width",width); //需要计算宽度
if (iScroll.bbs == null) {
iScroll.bbs = new BScroll("#bbsContentScroll", {
scrollX: true,
click: true,
eventPassthrough:'vertical'
});
} else {
iScroll.bbs.refresh();
}
用iScroll库也可以横竖滚动,我只用过纵的,没用过横的
拖拽
https://www.npmjs.com/package/vuedraggable
https://github.com/SortableJS/Sortable
<script src="${publicRoot}toolkit/vue/sortable.min.js"></script>
<script src="${publicRoot}toolkit/vue/vuedraggable.min.js"></script>
<draggable element="dl" :options="{filter:'.first'}" :list="classList" @update="datadragEnd">
<transition-group type="transition" : tag="div" >
<dd v-for="(item,index) in classList" :key="item.acId" : @click="deleteClass(index)">{{item.acName}}<i></i></dd>
</transition-group>
</draggable>
拖拽停止后,vue 中的classList顺序也直接变了,在datadragEnd方法中将classList更新到后台
:options="{filter:'.first'}"是设置哪些不可拖拽,加first样式