本文实例为大家分享了鼠标滚轮全屏切换的jquery代码,供大家参考,具体内容如下
html
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery鼠标滚动垂直全屏切换代码</title>
<base target="_blank" />
<link rel="stylesheet" type="text/css" href="css/css.css" rel="external nofollow" >
</head>
<body>
<div id="container">
<div class="section active" id="section0">
<div class="intro">
<h1 class="title">Section One</h1>
</div>
</div>
<div class="section" id="section1">
<div class="intro">
<h1 class="title">Section Two</h1>
</div>
</div>
<div class="section" id="section2">
<div class="intro">
<h1 class="title">Section Three</h1>
</div>
</div>
<div class="section" id="section3">
<div class="intro">
<h1 class="title">Section Three</h1>
</div>
</div>
<div class="section" id="section4">
<div class="intro">
<h1 class="title">Section Three</h1>
</div>
</div>
<div class="section" id="section5">
<div class="intro">
<h1 class="title">Section Three</h1>
</div>
</div>
<div class="section" id="section6">
<div class="intro">
<h1 class="title">Section Three</h1>
</div>
</div>
<div class="section" id="section7">
<div class="intro">
<h1 class="title">Section Three</h1>
</div>
</div>
<div class="section" id="section8">
<div class="intro">
<h1 class="title">Section Three</h1>
</div>
</div>
<div class="section" id="section9">
<div class="intro">
<h1 class="title">Section Three</h1>
</div>
</div>
</div>
<script src="http://down.hovertree.com/jquery/jquery-2.2.3.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/switchPage.js"></script>
<script type="text/javascript">
$(function(){
$("#container").switchPage({
'loop' : true,
'keyboard' : true,
'direction' : 'vertical'
});
});
</script>
</body>
</html>
css
h1, body, html {
padding: 0;
margin: 0;
}
html, body {
height: 100%;
overflow: hidden;
}
h1 {
font-size: 2em;
font-weight: normal;
}
#container, .section {
height: 100%;
position: relative;
}
#section0, #section1, #section2, #section3 {
background-color: #000;
background-size: cover;
background-position: 50% 50%;
}
#section0 {
background-color: #024BCE;
color: #fff;
text-shadow: 1px 1px 1px #333;
}
#section1 {
color: #fff;
text-shadow: 1px 1px 1px #333;
background-color: #31B81D;
}
#section2 {
background-color: #01B5F0;
color: #fff;
text-shadow: 1px 1px 1px #666;
}
#section3 {
color: #008283;
background-color: #5D0FF1;
text-shadow: 1px 1px 1px #fff;
}
#section4 {
color: #fff;
text-shadow: 1px 1px 1px #333;
background-color: #31B81D;
}
#section5 {
background-color: #01B5F0;
color: #fff;
text-shadow: 1px 1px 1px #666;
}
#section6 {
color: #008283;
background-color: #5D0FF1;
text-shadow: 1px 1px 1px #fff;
}
#section7 {
color: #fff;
text-shadow: 1px 1px 1px #333;
background-color: #31B81D;
}
#section8 {
background-color: #01B5F0;
color: #fff;
text-shadow: 1px 1px 1px #666;
}
#section9 {
color: #008283;
background-color: #5D0FF1;
text-shadow: 1px 1px 1px #fff;
}
.intro {
position: absolute;
top: 50%;
width: 100%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
text-align: center;
}
/*右侧导航*/
#pages {
position: fixed;
right: 10px;
top: 50%;
list-style: none;
}
#pages li {
width: 8px;
height: 8px;
border-radius: 50%;
background: #fff;
margin: 0 0 10px 5px;
}
#pages li.active {
width: 14px;
height: 14px;
border: 2px solid #FFFE00;
background: none;
margin-left: 0;
}
#section0 .title {
-webkit-transform: translateX(-100%);/*内容旋转*/
transform: translateX(-100%);
-webkit-animation: sectitle0 1s ease-in-out 100ms forwards;
animation: sectitle0 1s ease-in-out 100ms forwards; /*滑入页面*/
}
/*为支持上述滑入特效写的*/
@-webkit-keyframes
sectitle0 { 0% {
-webkit-transform: translateX(-100%);
transform: translateX(-100%);
}
100% {
-webkit-transform: translateX(0);
transform: translateX(0);
}
}
@keyframes
sectitle0 { 0% {
-webkit-transform: translateX(-100%);
transform: translateX(-100%);
}
100% {
-webkit-transform: translateX(0);
transform: translateX(0);
}
}
js
(function($) {
var defaults = {
'container': '#container', //容器
'sections': '.section', //子容器
'easing': 'ease', //特效方式,ease-in,ease-out,linear
'duration': 1000, //每次动画执行的时间
'pagination': true, //是否显示分页
'loop': false, //是否循环
'keyboard': true, //是否支持键盘
'direction': 'vertical', //滑动的方向 horizontal,vertical,
'onpageSwitch': function(pagenum) {}
};
var win = $(window);
var iIndex = 0; //当前section的索引
var arrElement = [];
var canScroll = true;
var container;
var sections;
var opts;
var flag=false;
var SP = $.fn.switchPage = function(options) {
opts = $.extend({}, defaults, options || {});
container = $(opts.container);
sections = container.find(opts.sections);
sections.each(function() {
arrElement.push($(this));
});
return this.each(function() {
if (opts.direction == 'horizontal') initLayout();
if (opts.pagination) initPagination();
})
}
//重置鼠标滚轮事件
$(document).on("mousewheel DOMMouseScroll", MouseWheelHandler);
function MouseWheelHandler(e) {
e.preventDefault();
var value = e.originalEvent.wheelDelta || -e.originalEvent.detail;
var delta = Math.max(-1, Math.min(1, value));
if (canScroll) {
if (delta < 0) {
SP.moveSectionDown();
} else {
SP.moveSectionUp();
}
}
return false;
}
//向上一张移
SP.moveSectionUp = function() {
if (iIndex) {
iIndex--;
} else if (opts.loop) {
iIndex = arrElement.length - 1;
}
scrollPage(arrElement[iIndex]);
}
//向下一张移
SP.moveSectionDown = function() {
if (iIndex < (arrElement.length - 1)) {
iIndex++
} else if (opts.loop) {
iIndex = 0;
}
scrollPage(arrElement[iIndex]);
}
//当设置横向移动时初始化横向页面
function initLayout() {
var width = (sections.length * 100) + '%',
cellwidth = (100 / sections.length).toFixed(2) + '%';
// container.width(width).addClass('left');
container.width(width);
sections.width(cellwidth).addClass('left');
}
//导航条初始化 hovertree.com
function initPagination() {
var length = sections.length;
var pageHtml = '<ul id="pages"><li class="active" id="dot_0"></li>'
for (var i = 1; i < length; i++) pageHtml += '<li id="dot_'+i+'"></li>';
pageHtml += '</ul>';
$("body").append(pageHtml);
flag=true;
if(flag==true){
$("li").click(function(){
var liId = $(this).attr("id");
var arr = liId.split('_');
iIndex=arr[1];
scrollPage(arrElement[iIndex]);
});
}
}
/*跳转到dot对应页面*/
function clickDot(){
}
//移动页面
function scrollPage(element) {
var dest = element.position();
if (dest == void 0) return;
initEffects(dest, element);
}
function isSupportCss(property) {
var body = $('body')[0];
for (var i = 0; i < property.length; i++) {
if (property[i] in body.style) {
return true;
}
}
return false;
}
//移动页面的核心函数
function initEffects(dest, element) {
canScroll = false;
var translate = "";
if (opts.direction == 'horizontal') {
translate = '-' + dest.left + 'px, 0px, 0px';
} else {
translate = '0px, -' + dest.top + 'px, 0px';
}
container.css({
'transform': "translate3d(" + translate + ")",
'transition': "all " + opts.duration + "ms " + opts.easing
});
container.on("webkitTransitionEnd msTransitionend mozTransitionend transitionend", function() {
canScroll = true;
});
element.addClass("active").siblings().removeClass('active');
if (opts.pagination) {
paginationHandler();
}
}
//每次页面移动时,修改导航栏 何问起
function paginationHandler() {
var pages = $('#pages li');
pages.eq(iIndex).addClass('active').siblings().removeClass('active');
}
var resizeId;
win.resize(function() {
clearTimeout(resizeId);
resizeId = setTimeout(function(){
rebuild();
}, 500);
});
function rebuild() {
var currentHeight = win.height();
var currentWidth = win.width();
var element = arrElement[iIndex];
if(opts.direction == "horizontal") {
var offsetLeft = element.offset().left;
if (Math.abs(offsetLeft) > (currentWidth/2) && iIndex < (arrElement.length - 1)){
iIndex++
}
}else {
var offsetTop = element.offset().top;
if (Math.abs(offsetTop) > (currentHeight/2) && iIndex < (arrElement.length - 1)){
iIndex++
}
}
var currentElement = arrElement[iIndex],
dest = currentElement.position();
initEffects(dest, currentElement);
if(opts.pagination) paginationHandler();
}
})(jQuery);
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
# jquery鼠标滚轮全屏切换
# jquery全屏切换
# jquery横向纵向鼠标滚轮
# 基于jQuery实现中英文切换导航条效果
# jquery结合html实现中英文页面切换
# jQuery实现鼠标移入移出事件切换功能示例
# jQuery实现的点击标题文字切换字体效果示例【测试可用】
# jquery实现图片放大点击切换
# jQuery实现百度登录框的动态切换效果
# 用jquery的attr方法实现图片切换效果
# jQuery实现图片与文字描述左右滑动自动切换的方法
# jquery淡化版banner异步图片文字效果切换图片特效
# 基于jquery插件制作左右按钮与标题文字图片切换效果
# jQuery实现的中英文切换功能示例
# 鼠标
# 全屏
# 滑入
# 分页
# 大家分享
# 具体内容
# 大家多多
# 跳转到
# 导航条
# js
# javascript
# min
# switchPage
# keyboard
# direction
# vertical
# function
# loop
# true
# hovertree
相关文章:
如何制作一个表白网站视频,关于勇敢表白的小标题?
大连网站制作公司哪家好一点,大连买房网站哪个好?
如何在Golang中使用encoding/gob序列化对象_存储和传输数据
专业网站设计制作公司,如何制作一个企业网站,建设网站的基本步骤有哪些?
武汉网站制作费用多少,在武汉武昌,建面100平方左右的房子,想装暖气片,费用大概是多少啊?
建站之星如何实现PC+手机+微信网站五合一建站?
关于BootStrap modal 在IOS9中不能弹出的解决方法(IOS 9 bootstrap modal ios 9 noticework)
动图在线制作网站有哪些,滑动动图图集怎么做?
如何选择适配移动端的WAP自助建站平台?
图册素材网站设计制作软件,图册的导出方式有几种?
矢量图网站制作软件,用千图网的一张矢量图做公司app首页,该网站并未说明版权等问题,这样做算不算侵权?应该如何解决?
建站OpenVZ教程与优化策略:配置指南与性能提升
c++ stringstream用法详解_c++字符串与数字转换利器
如何快速搭建高效WAP手机网站?
建站之星logo尺寸如何设置最合适?
枣阳网站制作,阳新火车站打的到仙岛湖多少钱?
如何用好域名打造高点击率的自主建站?
如何零基础开发自助建站系统?完整教程解析
网站制作外包价格怎么算,招聘网站上写的“外包”是什么意思?
如何通过VPS建站实现广告与增值服务盈利?
如何自定义建站之星模板颜色并下载新样式?
建站主机数据库如何配置才能提升网站性能?
建站一年半SEO优化实战指南:核心词挖掘与长尾流量提升策略
如何在云主机上快速搭建网站?
建站之星如何快速生成多端适配网站?
rsync同步时出现rsync: failed to set times on “xxxx”: Operation not permitted
Bpmn 2.0的XML文件怎么画流程图
如何选择可靠的免备案建站服务器?
如何快速查询网站的真实建站时间?
新网站制作渠道有哪些,跪求一个无线渠道比较强的小说网站,我要发表小说?
广州网站设计制作一条龙,广州巨网网络科技有限公司是干什么的?
如何配置FTP站点权限与安全设置?
学生网站制作软件,一个12岁的学生写小说,应该去什么样的网站?
如何快速搭建高效服务器建站系统?
怀化网站制作公司,怀化新生儿上户网上办理流程?
韩国服务器如何优化跨境访问实现高效连接?
建站之星如何防范黑客攻击与数据泄露?
C++用Dijkstra(迪杰斯特拉)算法求最短路径
建站之星后台密码遗忘或太弱?如何重置与强化?
如何用免费手机建站系统零基础打造专业网站?
深圳网站制作设计招聘,关于服装设计的流行趋势,哪里的资料比较全面?
如何在IIS中新建站点并解决端口绑定冲突?
潮流网站制作头像软件下载,适合母子的网名有哪些?
如何选择高性价比服务器搭建个人网站?
表情包在线制作网站免费,表情包怎么弄?
交易网站制作流程,我想开通一个网站,注册一个交易网址,需要那些手续?
浙江网站制作公司有哪些,浙江栢塑信息技术有限公司定制网站做的怎么样?
深圳网站制作平台,深圳市做网站好的公司有哪些?
如何快速搭建高效WAP手机网站吸引移动用户?
深圳网站制作公司好吗,在深圳找工作哪个网站最好啊?
*请认真填写需求信息,我们会在24小时内与您取得联系。