JQuery+CSS實(shí)現(xiàn)圖片上放置按鈕的方法
本文實(shí)例講述了JQuery+CSS實(shí)現(xiàn)圖片上放置按鈕的方法。分享給大家供大家參考。具體分析如下:
position:relative日常應(yīng)用的時(shí)候一般是設(shè)置給position:absolute;的父層的,
父層position:relative; 子層position:absolute;的話, 就是依照父層的邊界進(jìn)行定位的,
不然position:absolute 會(huì)逐層向上尋找設(shè)置了position:relative的元素邊界, 直到body元素..
第一種寫法(連同CSS一起追加進(jìn)去)
var freeOne="";
freeOne=$(".freePreviewOne").attr("data-url");
if(freeOne==null){
//沒有免費(fèi)視頻
}else{
$("#coursePicture").append("<a class='hide-650 fade5' "+
"style='top:94px;left:150px;position:absolute;z-index:100; " +
" width: 180px;height: 60px;border: 2px solid white;" +
"display: block;color: white;text-decoration: none;" +
"letter-spacing: 1px;font-size: 16px;line-height: 20px;" +
"text-align:center;padding-top:18px;" +
"background-color: rgba(0, 0, 0, 0.44);" +
"-webkit-backface-visibility: hidden;-webkit-transition: all .3s ease-in-out;" +
"-moz-transition: all .3s ease-in-out;-ms-transition: all .3s ease-in-out;" +
"-o-transition: all .3s ease-in-out;" +
"border-radius: 10px;'"+
"href='#modal' data-toggle='modal' "+
"data-url='"+freeOne+"'> "+
"<span class='contactus' style='font-size:26px;'>試 看</span> <span class='glyphicon glyphicon-play' style='font-size:20px;top:0;bottom:2px;'></span> </a>"
);
}
頁面:
<div class="es-row-wrap container-gap course-cover">
<div class="row row-5-7 course-cover-heading">
<div id="coursePicture" class="col-sm-5 picture hidden-xs" style="position: relative;">
<#if course.coverImage?has_content>
<img src="${course.coverImage}" class="img-responsive" width="436px" height="245px" />
<#else>
<img src="/resources/assets/img/default/course-large.png" class="img-responsive" />
</#if>
</div>
</div>
</div>
第二種寫法:
//在課程圖片上放置按鈕
/* <a class="button hide-650 fade5" href="#modal" data-toggle="modal" data-url="/course/hyjgz2np/lesson/preview?lectureId=hyjgz2np0.49618492345325650.04212287697009742"> <span class="contactus"><strong>試看</strong></span> </a>
*/
//$("#coursePicture").append("<a class='btn btn-sm btn-info' href='#' style='top:120px;left:180px;position:absolute;z-index:100;'>試看</a>");
var freeOne="";
freeOne=$(".freePreviewOne").attr("data-url");
if(freeOne==null){
//沒有免費(fèi)視頻
}else{
$("#coursePicture").append("<a class='freePreviewPicture hide-650 fade5' "+
"href='#modal' data-toggle='modal' "+
"data-url='"+freeOne+"'> "+
"<span class='contactus' style='font-size:26px;'>試 看</span> <span class='glyphicon glyphicon-play' style='font-size:20px;top:0;bottom:2px;'></span> </a>"
);
}
頁面:
<style>
.freePreviewPicture{
top:94px;
left:150px;
position:absolute;
z-index:100;
width: 180px;
height: 60px;
border: 2px solid white;
display: block;
color: white;text-decoration: none;
letter-spacing: 1px;font-size: 16px;
line-height: 20px;
text-align:center;padding-top:18px;
background-color: rgba(0, 0, 0, 0.44);
-webkit-backface-visibility: hidden;
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-ms-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
border-radius: 10px;
}
</style>
<div class="es-row-wrap container-gap course-cover">
<div class="row row-5-7 course-cover-heading">
<div id="coursePicture" class="col-sm-5 picture hidden-xs" style="position: relative;">
<#if course.coverImage?has_content>
<img src="${course.coverImage}" class="img-responsive" width="436px" height="245px" />
<#else>
<img src="/resources/assets/img/default/course-large.png" class="img-responsive" />
</#if>
</div>
</div>
</div>
運(yùn)行效果圖如下:

希望本文所述對(duì)大家的jQuery程序設(shè)計(jì)有所幫助。
相關(guān)文章
JQuery對(duì)表單元素的基本操作使用總結(jié)
這篇文章主要介紹了JQuery對(duì)表單元素的基本操作使用總結(jié),需要的朋友可以參考下2014-07-07
jquery獲取所有選中的checkbox實(shí)現(xiàn)代碼
下面小編就為大家?guī)硪黄猨query獲取所有選中的checkbox實(shí)現(xiàn)代碼。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-05-05
詳解jQuery的animate動(dòng)畫方法及動(dòng)畫排隊(duì)問題解決
這篇文章主要介紹了jQuery的animate動(dòng)畫方法及動(dòng)畫排隊(duì)問題解決的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)使用jQuery,感興趣的朋友可以了解下2021-05-05
Javascript中封裝window.open解決不兼容問題
window.open不兼容,其實(shí)不是, 因?yàn)椴荒苤苯訄?zhí)行, 必須通過用戶手動(dòng)觸發(fā)才行,下面有個(gè)實(shí)例,大家可以看看2014-09-09
JQuery的ajax基礎(chǔ)上的超強(qiáng)GridView展示
前面有個(gè)例子是使用jQuery的datatable插件來實(shí)現(xiàn)的能夠展開個(gè)詳細(xì)信息表的樣子。事實(shí)上.net的數(shù)據(jù)展示模式很好,如果配上jQuery的那些效果和AJAX功能是相當(dāng)?shù)貌诲e(cuò)。2009-09-09
jQuery+ajax實(shí)現(xiàn)文章點(diǎn)贊功能的方法
這篇文章主要介紹了jQuery+ajax實(shí)現(xiàn)文章點(diǎn)贊功能的方法,涉及jQuery基于ajax無刷新post提交實(shí)現(xiàn)點(diǎn)贊功能的具體步驟與相關(guān)技巧,需要的朋友可以參考下2015-12-12
使用jquery動(dòng)態(tài)加載Js文件和Css文件
這篇文章主要為大家詳細(xì)介紹了使用jquery動(dòng)態(tài)加載Js文件和Css文件的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2015-10-10
jquery UI Datepicker時(shí)間控件的使用方法(基礎(chǔ)版)
這篇文章主要介紹了jquery ui datepicker時(shí)間控件的使用方法,需要的朋友可以參考下2015-11-11

