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ì)話框效果(2)
- jQuery實(shí)現(xiàn)單擊按鈕遮罩彈出對(duì)話框效果(1)
- jQuery點(diǎn)擊按鈕彈出遮罩層且內(nèi)容居中特效
- jQuery實(shí)現(xiàn)點(diǎn)擊按鈕彈出可關(guān)閉層的浮動(dòng)層插件
- jQuery實(shí)現(xiàn)單擊按鈕遮罩彈出對(duì)話框(仿天貓的刪除對(duì)話框)
- 基于Jquery的仿Windows Aero彈出窗(漂亮的關(guān)閉按鈕)
- jquery實(shí)現(xiàn)界面點(diǎn)擊按鈕彈出懸浮框
相關(guān)文章
使用jquery 簡(jiǎn)單實(shí)現(xiàn)下拉菜單
這里給大家展示了一例使用jQuery實(shí)現(xiàn)下拉菜單效果,代碼非常簡(jiǎn)潔,推薦給小伙伴們2015-01-01
編寫(xiě)自己的jQuery插件簡(jiǎn)單實(shí)現(xiàn)代碼
用了這長(zhǎng)時(shí)間的jQuery,一直也沒(méi)怎么寫(xiě)過(guò)jQuery插件,今天簡(jiǎn)單實(shí)現(xiàn)倆個(gè)插件,鞏固下基礎(chǔ)知識(shí)。2011-04-04
jquery地址欄鏈接與a標(biāo)簽鏈接匹配之特效代碼總結(jié)
jquery如何獲取地址欄參數(shù),改變地址欄樣式,接下來(lái),通過(guò)本篇文章給大家分享jquery地址欄鏈接與a標(biāo)簽鏈接匹配之特效代碼總結(jié),需要的朋友可以參考下2015-08-08
jquery 實(shí)時(shí)監(jiān)聽(tīng)輸入框值變化的完美方法(必看)
下面小編就為大家?guī)?lái)一篇jquery 實(shí)時(shí)監(jiān)聽(tīng)輸入框值變化的完美方法(必看)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-01-01
讓jQuery與其他JavaScript庫(kù)并存避免沖突的方法
為了解決jQuery和其他JavaScript庫(kù)中$()函數(shù)的沖突,需要取消jQuery的$()函數(shù),下面有個(gè)不錯(cuò)的方法,感興趣的朋友可以參考下2013-12-12
基于jQuery實(shí)現(xiàn)點(diǎn)擊最后一行實(shí)現(xiàn)行自增效果的表格
現(xiàn)在任何事務(wù)都追求效率和人性化,當(dāng)然網(wǎng)頁(yè)效果也是如此,如果一個(gè)可以編輯數(shù)據(jù)的表格,編輯到最后一行的時(shí)候,點(diǎn)擊可以自動(dòng)添加一行,這樣算是一個(gè)比較人性化的效果,可以免去一絲勞頓之苦,下面分享一段這樣的代碼2016-01-01

