国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

基于mootools的圓角邊框擴展代碼

2019-11-21 00:45:37
字體:
來源:轉載
供稿:網友
JQuery下面有個擴展是用純JS生成的圓角,不過和DIV+CSS拼出來是一樣的道理,圓角看上去都比較粗糙。

用背景圖片要好看得多,問題是不能拉伸,最簡單做法就是用四個角小圖片加邊框拼出來。不過這樣多出N多圖片,一堆亂七八糟的代碼,相當不爽。

有一個很有技巧的方法,用一張大圖片+CSS來做,原理如下。
 
用一張大的背景圖片做圓角,用CSS分別取四個角和邊再拼成一個DIV。這樣不僅可以解決圓角,還可以生成其它特殊的邊框(比如陰影)。
但是每次使用都要加CSS也很不爽,于是用mootools寫了一個Element類的擴展。
復制代碼 代碼如下:

setBorder
Element.implement({
setBorder: function(pic, len) {
/// <summary>
/// 設定容器邊框(圖片).
/// 已測div
/// </summary>
/// <param name="pic">圖片地址</param>
/// <param name="len">邊框寬度</param>
/// <returns type="Element" />
var content = this.clone();
var width = this.getSize().x + len * 2;
var height = this.getSize().y + len * 2;
this.empty().setStyles({ 'width': width, 'height': height });
var lt = new Element('div', {
'styles': {
'width': len,
'height': len,
'float': 'left',
'background': 'url(' + pic + ') no-repeat left top'
}
});
var rt = new Element('div', {
'styles': {
'width': width - len,
'height': len,
'float': 'left',
'background': 'url(' + pic + ') no-repeat right top'
}
});
var lb = new Element('div', {
'styles': {
'width': len,
'height': height - len,
'float': 'left',
'background': 'url(' + pic + ') no-repeat left bottom'
}
});
var rb = new Element('div', {
'styles': {
'width': width - len,
'height': height - len,
'float': 'left',
'background': 'url(' + pic + ') no-repeat right bottom'
}
});
content.inject(rb, 'top');
lt.inject(this, 'top');
rt.injectBottom(this);
lb.injectBottom(this);
rb.injectBottom(this);
return this;
}
});



這樣在頁面上直接調用setBorder方法傳個背景圖片,邊框寬度進去就行了。

HTML代碼
復制代碼 代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script type="text/javascript" src="mootools.js"></script>
<script type="text/javascript">
Element.implement({
setBorder: function(pic, len) {
/// <summary>
/// 設定容器邊框(圖片).
/// 已測div
/// </summary>
/// <param name="pic">圖片地址</param>
/// <param name="len">邊框寬度</param>
/// <returns type="Element" />
var content = this.clone();
var width = this.getSize().x + len * 2;
var height = this.getSize().y + len * 2;
this.empty().setStyles({ 'width': width, 'height': height });
var lt = new Element('div', {
'styles': {
'width': len,
'height': len,
'float': 'left',
'background': 'url(' + pic + ') no-repeat left top'
}
});
var rt = new Element('div', {
'styles': {
'width': width - len,
'height': len,
'float': 'left',
'background': 'url(' + pic + ') no-repeat right top'
}
});
var lb = new Element('div', {
'styles': {
'width': len,
'height': height - len,
'float': 'left',
'background': 'url(' + pic + ') no-repeat left bottom'
}
});
var rb = new Element('div', {
'styles': {
'width': width - len,
'height': height - len,
'float': 'left',
'background': 'url(' + pic + ') no-repeat right bottom'
}
});
content.inject(rb, 'top');
lt.inject(this, 'top');
rt.injectBottom(this);
lb.injectBottom(this);
rb.injectBottom(this);
return this;
}
});
window.addEvent('domready', function() {
$('demo').getElements('div').each(function(d) {
d.setBorder('border.png', 8);
});
});
</script>
</head>
<body>
<div id="demo">
<div style="width:150px; height:100px;">
<div style="width:100%; height:100%; background-color:Red;"></div>
</div>
<div style="width:80px; height:130px;">
<div style="width:100%; height:100%; background-color:Green;"></div>
</div>
</div>
</body>
</html>

 
顯顯示效果
mootools邊框demo http://demo.VeVB.COm/js/mootools_yj/demo.htm
打包下載

[Ctrl+A 全選 注:如需引入外部Js需刷新才能執行]

以前用Jquery也寫過一個,居然找不著了,不過原理是一樣的。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 福海县| 阿坝| 九龙城区| 铜川市| 西昌市| 祁东县| 华阴市| 桓台县| 通榆县| 紫阳县| 绍兴县| 余庆县| 佳木斯市| 洛川县| 靖西县| 葵青区| 杭州市| 和静县| 沙雅县| 蓬安县| 安乡县| 抚州市| 确山县| 平定县| 礼泉县| 额尔古纳市| 闵行区| 南投县| 江源县| 濮阳市| 巴塘县| 深州市| 汶上县| 鹤山市| 青神县| 上饶县| 麟游县| 齐齐哈尔市| 荥经县| 天津市| 皋兰县|