jQuery實(shí)現(xiàn)首頁(yè)懸浮框
本文實(shí)例為大家分享了jQuery實(shí)現(xiàn)首頁(yè)懸浮框的具體代碼,供大家參考,具體內(nèi)容如下
基于jQuery實(shí)現(xiàn)首頁(yè)懸浮框,如下圖所示
1、在頁(yè)面中引入jQuery.bay-window.js,jQuery.bay-window.js的代碼如下:
!function($){ ? /** ? ?* Description: jquery飄窗插件,可自適應(yīng)瀏覽器寬高的變化 ? ?* Author: ddqre12345 ? ?* CreateTime: 2017.5.3 ? ?* param: args={startL:default, startT:default, angle:-Math.PI/4, speed: 125} ? ?* 參數(shù)說(shuō)名: startL飄窗初始時(shí)距離左邊的距離, startT飄窗初始化距離頂部的距離, angle飄窗初始運(yùn)動(dòng)方向, speed運(yùn)動(dòng)速度(px/s) ? ?*/ ? $.fn.autoMove = function(args){ ? ? //先定義一些工具函數(shù)判斷邊距 ? ? function isTop(pos, w_w, w_h, d_w, d_h){//飄窗到達(dá)上邊距 ? ? ? return (pos.top<=0) ? true : false; ? ? } ? ? function isBottom(pos, w_w, w_h, d_w, d_h){//飄窗到達(dá)下邊距 ? ? ? return (pos.top>=(w_h-d_h)) ? true : false; ? ? } ? ? function isLeft(pos, w_w, w_h, d_w, d_h){//飄窗到達(dá)左邊距 ? ? ? return (pos.left<=0) ? true : false; ? ? } ? ? function isRight(pos, w_w, w_h, d_w, d_h){//飄窗到達(dá)右邊距 ? ? ? 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; ? ? ? //位置及參數(shù)的初始化 ? ? ? 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']};//飄窗位置對(duì)象 ? ? ? var that = $(this); ? ? ? var angle= setobj.angle; ? ? ? var time = 10;//控制飄窗運(yùn)動(dòng)效果,值越小越細(xì)膩 ? ? ? var step = setobj.speed * (time/1000);//計(jì)算運(yùn)動(dòng)步長(zhǎng) ? ? ? var decoration = {x:step*Math.cos(angle), y:step*Math.sin(angle)};//計(jì)算二維上的運(yùn)動(dòng)增量 ? ? ? var mvtid; ? ? ? $(window).on('resize', function(){//窗口大小變動(dòng)時(shí)重新設(shè)置運(yùn)動(dòng)相關(guān)參數(shù) ? ? ? ? ? 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動(dòng)畫(huà)函數(shù)使其更加平滑 ? ? ? ? mvtid = setTimeout(move, time);//遞歸調(diào)用,使飄窗連續(xù)運(yùn)動(dòng) ? ? ? } ? ? ? move();//觸發(fā)動(dòng)作 ? ? ? that.on('mouseenter', function(){ clearTimeout(mvtid) });//添加鼠標(biāo)事件 ? ? ? that.on('mouseleave', function(){ move() }); ? ? }); ? }; //end plugin definition }(jQuery);
2、接口獲取懸浮框相關(guān)的數(shù)據(jù)
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頁(yè)面引入相關(guān)html代碼
<template v-if="piaoc != null"> ? ? ? <template v-if="piaoc.is_open_float_win == '1'"> ? ? ? ? ? ? ? ? <div class="automv" :style="'display: block;height:'+piaoc.open_float_height+';width:'+piaoc.open_float_width"> ? ? ? ? ? ? ? ? ? ? <span>×</span> ? ? ? ? ? ? ? ? ? ? <a :href="piaoc.open_float_url" rel="external nofollow" > ? ? ? ? ? ? ? ? ? ? ? ? <template v-if="piaoc.open_float_image"> ? ? ? ? ? ? ? ? ? ? ? ? ? ? <img :src="piaoc.open_float_image_name+'!y'" alt=""> ? ? ? ? ? ? ? ? ? ? ? ? </template> ? ? ? ? ? ? ? ? ? ? ? ? <template v-else> ? ? ? ? ? ? ? ? ? ? ? ? ? ? <img src="../image/piaochuang.jpg" alt=""> ? ? ? ? ? ? ? ? ? ? ? ? </template> ? ? ? ? ? ? ? ? ? ? </a> ? ? ? ? ? ? ? ? </div> ? ? ? ? ? ? </template> ? ? ? ? ? ? <template v-else> ? ? ? ? ? ? ? ? <div class="automv" style="display: none;"></div> ? ? ? </template> </template>
4、相關(guān)懸浮框的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; }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 使用jQuery UI的tooltip函數(shù)修飾title屬性的氣泡懸浮框
- jQuery實(shí)現(xiàn)單擊按鈕遮罩彈出對(duì)話(huà)框效果(2)
- jQuery實(shí)現(xiàn)單擊按鈕遮罩彈出對(duì)話(huà)框效果(1)
- jQuery點(diǎn)擊按鈕彈出遮罩層且內(nèi)容居中特效
- jQuery實(shí)現(xiàn)點(diǎn)擊按鈕彈出可關(guān)閉層的浮動(dòng)層插件
- jQuery實(shí)現(xiàn)單擊按鈕遮罩彈出對(duì)話(huà)框(仿天貓的刪除對(duì)話(huà)框)
- 基于Jquery的仿Windows Aero彈出窗(漂亮的關(guān)閉按鈕)
- jquery實(shí)現(xiàn)界面點(diǎn)擊按鈕彈出懸浮框
相關(guān)文章
formvalidator驗(yàn)證插件中有關(guān)ajax驗(yàn)證問(wèn)題
jquery formvalidator插件是不錯(cuò)的國(guó)產(chǎn)驗(yàn)證插件了,做點(diǎn)普通的校驗(yàn)也是很方便的,但最近遇到個(gè)問(wèn)題,發(fā)現(xiàn)如果表單整個(gè)表單是AJAX提交時(shí),就不能按傳統(tǒng)的做法了2013-01-01JQuery入門(mén)——用bind方法綁定事件處理函數(shù)應(yīng)用介紹
bind()功能是為每個(gè)選擇元素的事件綁定處理函數(shù),感興趣的你可以了解下它的語(yǔ)法bind(type, [data], fn),參數(shù)data是作為event.data屬性值傳遞對(duì)象的額外數(shù)據(jù)對(duì)象,好好學(xué)習(xí)希望本可以幫助到你2013-02-02jquery中g(shù)et,post和ajax方法的使用小結(jié)
本篇文章主要是對(duì)jquery中g(shù)et,post和ajax方法的使用進(jìn)行了詳細(xì)的介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-02-02深入理解jQuery中l(wèi)ive與bind方法的區(qū)別
本篇文章主要是對(duì)jQuery中l(wèi)ive與bind方法的區(qū)別進(jìn)行了詳細(xì)的分析介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2013-12-12自己動(dòng)手制作jquery插件之自動(dòng)添加刪除行功能介紹
這個(gè)插件的上篇訪(fǎng)問(wèn)量很不好,幾乎是我寫(xiě)的文章里最少的點(diǎn)擊量的了,不知道是不是因?yàn)榇蠹覍?duì)我說(shuō)的這個(gè)插件不感興趣還是說(shuō)我寫(xiě)的東西技術(shù)含量太差了,呵,那我只能孤芳自賞了2011-10-10利用JQuery的load函數(shù)動(dòng)態(tài)加載其它頁(yè)面的內(nèi)容的實(shí)現(xiàn)代碼
利用JQuery的load函數(shù)動(dòng)態(tài)加載別的頁(yè)面的代碼,方便實(shí)時(shí)獲取別的頁(yè)面的內(nèi)容。2010-12-12jQuery實(shí)現(xiàn)左側(cè)導(dǎo)航模塊的顯示與隱藏效果
這篇文章主要介紹了jQuery實(shí)現(xiàn)左側(cè)導(dǎo)航模塊的顯示與隱藏效果,涉及jQuery相應(yīng)鼠標(biāo)事件動(dòng)態(tài)操作頁(yè)面元素樣式的相關(guān)技巧,需要的朋友可以參考下2016-07-07使用jQuery中的wrap()函數(shù)操作HTML元素的教程
wrap(),顧名思義,就是包裹的意思,就是在你所在器外層包裹一層?xùn)|西,接下來(lái)我們就詳細(xì)來(lái)看使用jQuery中的wrap()函數(shù)操作HTML元素的教程:2016-05-05