jQuery簡單實現中間浮窗效果_jquery

來源:互聯網
上載者:User

本文執行個體講述了jQuery簡單實現中間浮窗效果。分享給大家供大家參考,具體如下:

basic.css:

/** -- 樣式說明 --* 最大優先實現法,全域能實現不用地區,地區能實現不用模板,模板能實現不用介面,介面能實現不用標籤* g - 全域* t - 地區* m - 模板* ui - 介面* lb - 標籤* j - 指令碼 只使用在有JS操作的樣式*//*公用樣式*/html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp, small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, figure, footer, header, menu, nav, section, time, mark, audio, video, details, summary{ margin:0; padding:0;}body{ font-family:Helvetica,Tahoma,Arial,sans-serif; color:#333; font-size:16px; background-color:#fff;}input, select, textarea{ font-family:Helvetica,Tahoma,Arial,sans-serif; background:#fff; margin:0; padding:0; outline:none;}textarea{ resize:none;}img{ border:none;}i, em{ font-style:normal;}ul li{ list-style-type:none;}a{ color:#06f; text-decoration:none;}a:hover{ color:#06f; text-decoration:underline;}/*全域樣式*/.g-fl{ float:left;}.g-fr{ float:right;}.g-c{ clear:both;}

index.html:

<!DOCTYPE html><html lang="zh-cn"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no"><title>中間浮窗</title><link href="css/basic.css" rel="stylesheet"><script src="js/jquery-1.10.1.min.js"></script></head><body><div style="height:10000px;"></div><style type="text/css">/*建議先隱藏浮窗的樣式 display:none*/.j-fixcenter{ height:120px; width:219px; background:#f60; display:none; position:fixed; }</style><div id="fixCenter" class="j-fixcenter">  <img src="img/fixCenter.jpg" width="219" height="120" usemap="#fixCenterMap">  <!--繪製地圖,把圖片哪個位置要點擊的繪製出來-->  <map name="fixCenterMap" id="fixCenterMap">    <area shape="rect" coords="175,0,219,30" href="javascript:void();" id="closeFixCenter" />    <area shape="rect" coords="0,30,219,94" href ="###2" />    <area shape="rect" coords="0,94,219,120" href ="###3" />  </map></div><script type="text/javascript">$(function(){  //調用浮窗方法  fixCenter();});//當調整瀏覽器視窗的大小時,發生 resize 事件$(window).resize(function(){  //重設浮窗定位  fixCenterGetPosition();});function fixCenter(){  //擷取浮窗定位  fixCenterGetPosition();  //擷取在浮窗的元素ID  var fid = $("#fixCenter");  //漸層顯示元素  fid.fadeIn(600);  //關閉按鈕的點擊事件  $("#closeFixCenter").click(function(){    //漸層隱藏元素,三秒後重新顯示    fid.fadeOut(600).delay(3000).fadeIn(600);  });}function fixCenterGetPosition(){  var fid = $("#fixCenter");  //擷取當前視窗的高度  var h = $(window).height();  //擷取當前視窗的寬度  var w = $(window).width();  //計算要定位左側距離  var left = (w/2) - parseInt(fid.css("width")) / 2;  //計算要定位上側距離  var top = (h/2) - parseInt(fid.css("height")) / 2;  //設定定位距離的樣式  fid.css({"left":(left) + "px", "top": (top) + "px" });}</script></body></html>

效果圖:

更多關於jQuery相關內容感興趣的讀者可查看本站專題:《jQuery擴充技巧總結》、《jQuery常用外掛程式及用法總結》、《jQuery拖拽特效與技巧總結》、《jQuery表格(table)操作技巧匯總》、《jquery中Ajax用法總結》、《jQuery常見經典特效匯總》、《jQuery動畫與特效用法總結》及《jquery選取器用法總結》

希望本文所述對大家jQuery程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.