編寫簡單的jQuery提示插件
很簡單的代碼,就不多廢話了。
代碼:
/**
* 2014年11月13日
* 提示插件
*/
(function ($) {
$.fn.tips = function (text) {
var divtipsstyle = "position: absolute; left: 0; top: 0; background-color: #dceaf2; padding: 3px; border: solid 1px #6dbde4; visibility: hidden; line-height:20px; ";
$("body").append("<div class='div-tips' style='" + divtipsstyle + "'>" + text + "</div>");
var divtips = $(".div-tips");
divtips.css("visibility", "visible");
var top = this.offset().top - divtips.height() - 8;
var left = this.offset().left;
divtips.css("top", top);
divtips.css("left", left);
$(document).mousemove(function (e) {
var top = e.clientY + $(window).scrollTop() - divtips.height() - 12;
var left = e.clientX;
divtips.css("top", top);
divtips.css("left", left);
});
};
$.fn.removetips = function (text) {
$(".div-tips").remove();
};
})($);
效果圖(鼠標(biāo)移到商品上面,會在下面顯示一個方形的商品詳情框):
很實用吧,小伙伴們自由發(fā)揮下,結(jié)合到自己的項目中吧
相關(guān)文章
jQuery實現(xiàn)的類似淘寶網(wǎng)站搜索框樣式代碼分享
這篇文章主要介紹了類似淘寶網(wǎng)站搜索框樣式實現(xiàn)代碼,推薦給大家,有需要的小伙伴可以參考下。2015-08-08jQuery+json實現(xiàn)動態(tài)創(chuàng)建復(fù)雜表格table的方法
這篇文章主要介紹了jQuery+json實現(xiàn)動態(tài)創(chuàng)建復(fù)雜表格table的方法,涉及jQuery針對json數(shù)據(jù)的解析與表格動態(tài)創(chuàng)建操作相關(guān)技巧,需要的朋友可以參考下2016-10-10