最近因为项目的需要,使用了一个jquery插件。把插件下下来后,很快我就发现,很多默认的插件style不符合项目要求,必须要被修改。
在这个过程中,我发现自己先后使用了多种不同的方法实现插件style的定制化。很高兴最后找到了我认为最好的方法,对css的认识也加深了不少,感触颇多。这篇文章就是对这些新的css的认识的一个梳理。
2jquery 插件style 定制化方法
2.1 初始化插件时输入定制化对象
做的比较好的插件会在初始化时允许输入定制化对象。
如果输入定制化对象,插件会使用定制化对象中的值,例如,
代码如下:
var adgallerysetting = {
width: 600, // width of the image, set to false and it will read the css width
height: 400, // height of the image, set to false and it will read the css height
}
var galleries = $('.ad-gallery').adgallery(adgallerysetting);
. 代码如下:
var adgallerysetting = {
// all callbacks has the adgallery objects as 'this' reference
callbacks: {
// this gets fired right before old_image is about to go away, and new_image
// is about to come in
beforeimagevisible: function(new_image, old_image) {
// do something wild!
var thing = "this is it";
//change the plugin enhanced page
$(".ad-gallery .ad-image-wrapper .ad-image").removeattr("style");
$(".ad-gallery .ad-image-wrapper .ad-image").css("width", "100%");
var width = $(".ad-gallery .ad-image-wrapper .ad-image img").attr("width");
$(".ad-gallery .ad-image-wrapper .ad-image img").attr("width", "100%");
$(".ad-gallery .ad-image-wrapper .ad-image .img").attr("width", 100%);
$(".ad-gallery .ad-image-wrapper .ad-image").attr("height", 100%);
}
}
};
. 代码如下:
#descriptions .ad-image-description {
position: absolute;
}
#descriptions .ad-image-description .ad-description-title {
display: block;
}
.ad-gallery .ad-image-wrapper .ad-image {
width: 100% ! important;
left: 0px ! important;
}
如对本文有疑问, 点击进行留言回复!!
JavaScript 好题汇总分享(持续更新,看到好题就写)
XMLHttpRequest 2级 &&进度事件&&JSONP
使用递归原生实现拷贝&&最简单的方法实现深拷贝
网友评论