jQuery如何实现首页悬浮框
发表于:2024-10-06 作者:千家信息网编辑
千家信息网最后更新 2024年10月06日,这篇"jQuery如何实现首页悬浮框"文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇"j
千家信息网最后更新 2024年10月06日jQuery如何实现首页悬浮框
这篇"jQuery如何实现首页悬浮框"文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇"jQuery如何实现首页悬浮框"文章吧。
基于jQuery实现首页悬浮框,如下图所示
1、在页面中引入jQuery.bay-window.js,jQuery.bay-window.js的代码如下:
!function($){ /** * Description: jquery飘窗插件,可自适应浏览器宽高的变化 * Author: ddqre12345 * CreateTime: 2017.5.3 * param: args={startL:default, startT:default, angle:-Math.PI/4, speed: 125} * 参数说名: startL飘窗初始时距离左边的距离, startT飘窗初始化距离顶部的距离, angle飘窗初始运动方向, speed运动速度(px/s) */ $.fn.autoMove = function(args){ //先定义一些工具函数判断边距 function isTop(pos, w_w, w_h, d_w, d_h){//飘窗到达上边距 return (pos.top<=0) ? true : false; } function isBottom(pos, w_w, w_h, d_w, d_h){//飘窗到达下边距 return (pos.top>=(w_h-d_h)) ? true : false; } function isLeft(pos, w_w, w_h, d_w, d_h){//飘窗到达左边距 return (pos.left<=0) ? true : false; } function isRight(pos, w_w, w_h, d_w, d_h){//飘窗到达右边距 return (pos.left>=(w_w-d_w)) ? true : false; } return this.each(function(){ var w_w = parseInt($(window).width()), w_h = parseInt($(window).height()), d_w = parseInt($(this).width()), d_h = parseInt($(this).height()), d_l = (w_w-d_w)/2, d_t = (w_h-d_h)/2, max_l = w_w - d_w; max_t = w_h - d_h; //位置及参数的初始化 var setobj = $.extend({startL:d_l, startT:d_t, angle:Math.PI/4, speed:100}, args); $(this).css({position: 'fixed', left: setobj['startL']+'px', top: setobj['startT']+'px'}); var position = {left: setobj['startL'], top: setobj['startT']};//飘窗位置对象 var that = $(this); var angle= setobj.angle; var time = 10;//控制飘窗运动效果,值越小越细腻 var step = setobj.speed * (time/1000);//计算运动步长 var decoration = {x:step*Math.cos(angle), y:step*Math.sin(angle)};//计算二维上的运动增量 var mvtid; $_(window).on('resize', function(){//窗口大小变动时重新设置运动相关参数 w_w = parseInt($(window).width()); w_h = parseInt($(window).height()); max_l = w_w - d_w; max_t = w_h - d_h; }); function move(){ position.left += decoration.x; position.top += decoration.y; if(isLeft(position, w_w, w_h, d_w, d_h)||isRight(position, w_w, w_h, d_w, d_h)){ decoration.x = -1*decoration.x; } if(isRight(position, w_w, w_h, d_w, d_h)){ position.left = max_l; } if(isTop(position, w_w, w_h, d_w, d_h)||isBottom(position, w_w, w_h, d_w, d_h)){ decoration.y = -1*decoration.y; } if(isBottom(position, w_w, w_h, d_w, d_h)){ position.top = max_t; } //that.css({left:position.left, top:position.top}); that.stop().animate({left:position.left, top:position.top}, time);//改用jquery动画函数使其更加平滑 mvtid = setTimeout(move, time);//递归调用,使飘窗连续运动 } move();//触发动作 that.on('mouseenter', function(){ clearTimeout(mvtid) });//添加鼠标事件 that.on('mouseleave', function(){ move() }); }); }; //end plugin definition}(jQuery);
2、接口获取悬浮框相关的数据
http("POST", "/School/detail", {"id":s_id}, function (e) { vm.piaoc = e.data; vm.$nextTick(function () { $('.automv').autoMove({angle:-Math.PI/4, speed:50}); $("body").on("click",".automv span",function(){ $(this).parent().find("a").removeAttr("href"); $(this).parent().hide(); }) }) })
3、html页面引入相关html代码
4、相关悬浮框的css
.automv{ width: 200px; height: 150px; z-index: 1032; position: relative;}.automv a{ display: block; width: 100%; height: 100%;}.automv a img{ width: 100%; height: 100%;}.automv span{ position: absolute; right: 3px; top: 3px; font-size: 26px; color: #fff; cursor: pointer; display: block; width: 20px; height: 20px; line-height: 20px; text-align: center;}.automv:hover span{ color: #fc87a3;}
以上就是关于"jQuery如何实现首页悬浮框"这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注行业资讯频道。
运动
内容
首页
代码
位置
函数
参数
文章
知识
篇文章
页面
细腻
平滑
上边
事件
价值
动作
动画
增量
大小
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网页导航软件开发
服务器 网站安全维护
奇安信网络安全攻防演练总结
湛江数据链软件开发报价表
互联网科技与产业结合
检索中文期刊论文用哪几个数据库
计算机网络技术抓包实验报告
冒险岛2服务器位置
我的世界015服务器
桂林app软件开发解决方案
公安局 网络安全 建设
视频特效软件开发
从高中开始学习网络技术
软件开发是高科技吗
查询mysql数据库死锁的语句
支付宝互联网科技股
cdn服务器软件
软件开发工作周志
自考计算机网络技术试卷
高亿联合网络技术有限公司
构筑网络安全屏障的守护者
数据库技术大题
瓷都取名软件开发
林场网络安全自查情况
河南数据软件开发五星服务
苍南新能源刀片服务器欢迎咨询
达梦数据库客户端怎么连接
宝山区服务器设备回收公司哪家好
嘉兴企业软件开发培训
合肥网络安全运维