何使用css實(shí)現(xiàn)漸變跟隨鼠標(biāo)光標(biāo)的懸停效果。如下圖:
實(shí)現(xiàn)思路:
html:
<button class="mouse-cursor-gradient-tracking">
<span>Hover me</span>
</button>
css:
/*按鈕基本樣式*/
.mouse-cursor-gradient-tracking {
position: relative;
background: #7983ff;
padding: 0.5rem 1rem;
font-size: 1.2rem;
border: none;
color: white;
cursor: pointer;
outline: none;
overflow: hidden;
}
.mouse-cursor-gradient-tracking span {
position: relative;
}
/*按鈕漸變背景,這里使用偽類實(shí)現(xiàn),并且使用transform動(dòng)畫(huà)*/
.mouse-cursor-gradient-tracking:before {
--size: 0; /*漸變背景尺寸*/
content: '';
position: absolute;
left: var(--x);
top: var(--y);
width: var(--size);
height: var(--size);
/*背景漸變*/
background: radial-gradient(circle closest-side, pink, transparent);
/*動(dòng)畫(huà)效果*/
transform: translate(-50%, -50%);
transition: width 0.2s ease, height 0.2s ease;
}
/*鼠標(biāo)經(jīng)過(guò)按鈕時(shí)*/
.mouse-cursor-gradient-tracking:hover:before {
--size: 200px;
}
javascript:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
#box{
width: 300px;
height: 300px;
border: 2px solid black;
background-color: yellow;
}
</style>
<script>
var w;
var h;
// currentStyle IE
var i=1;
var j=1;
var c=0;
function cool(name,value){
var odiv=document.getElementById('box');
var obj_w=getComputedStyle(odiv,false).width;
var obj_h=getComputedStyle(odiv,false).height;
var obj_c=getComputedStyle(odiv,false).backgroundColor;
if(name=='width'){
w=parseInt(obj_w)+parseInt(value)*i+'px';
i+=1;
odiv.style[name]=w;
}
else if(name=='height'){
h=parseInt(obj_h)+parseInt(value)*j+'px';
j+=1;
odiv.style[name]=h;
}else if(name=='backgroundColor')
{
if(c==value.length)
c=0;
odiv.style[name]=value[c]
c+=1;
}
}
</script>
</head>
<body>
<input type="button" value="變寬" onclick="cool('width','100');"/>
<input type="button" value="變高" onclick="cool('height','100');"/>
<input type="button" value="變紅" onclick="cool('backgroundColor',['red','yellow','pink','purple']);"/>
<br>
<div id="box"></div>
</body>
</html>
為了方便用戶更好使用web組態(tài),最近提供了用戶自定義組件的功能。在實(shí)施項(xiàng)目中就可以使用自己的組件了!
首先我們登陸系統(tǒng)就會(huì)看到新增的組件管理選項(xiàng) 如下圖:
點(diǎn)擊添加組件選擇2D組件我們就可以建立一個(gè)自己的組件了
《組件設(shè)計(jì)器》由 基礎(chǔ)設(shè)置(包括名稱 code 類型 狀態(tài) icon 次序號(hào) )HTML編輯區(qū)域 CSS編輯區(qū)域 JS編輯區(qū)域 和預(yù)覽區(qū)域組成。
首先我們給組件 起一個(gè)‘名字’ 和 ‘code’,在url輸入框中可以給組件設(shè)置一個(gè)icon。點(diǎn)擊保存系統(tǒng)會(huì)為我們建立一個(gè)組件模板。
由于web組態(tài)是由vue開(kāi)發(fā)的所以開(kāi)發(fā)組件也需要vue的的基礎(chǔ)知識(shí)。建議去看下vue的教程及生命周期,以方便開(kāi)發(fā)組件。以下我附上vue生命周期圖及組件代碼。
我們就開(kāi)始設(shè)計(jì)一個(gè)炫酷的按鈕作為例子
HTML代碼如下:
<a href="#" class="btn123" :style="imrstyle" v-show="controlProp.commProp.visible">{{controlProp.textProp.text}}</a>
這里:
style="imrstyle":樣式 在web組態(tài)設(shè)計(jì)器中呈現(xiàn)的樣式
v-show="controlProp.commProp.visible":可見(jiàn)性 在web組態(tài)設(shè)計(jì)器中可實(shí)現(xiàn)顯示或閃爍
{{controlProp.textProp.text}}:文本 對(duì)應(yīng)組件的文本屬性
更多屬性請(qǐng)參考:http://krmes.com:8000/md/design/#%E7%BB%84%E4%BB%B6%E5%9F%BA%E7%A1%80%E5%B1%9E%E6%80%A7
CSS代碼如下:
.btn123 {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
box-sizing: border-box;
z-index: 1;
}
.btn123:hover {
animation: animate 8s linear infinite;
}
@keyframes animate {
0% {
background-position: 0%;
}
100% {
background-position: 400%;
}
}
.btn123::before {
content: '';
position: absolute;
top: -5px;
left: -5px;
right: -5px;
bottom: -5px;
z-index: -9999;
background: linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);
background-size: 400%;
border-radius: 40px;
opacity: 0;
transition: 0.5s;
}
.btn123:hover::before {
filter: blur(20px);
opacity: 1;
animation: animate 8s linear infinite;
}
JS代碼如下:
export default {
props: {
controlProp: Object //作為web組態(tài)設(shè)計(jì)器的繼承屬性
},
data() {
return {
}
},
computed: {
imrstyle: function () { //imrstyle 作為web組態(tài)設(shè)計(jì)器的控制樣式
let maxWidth=this.controlProp.commProp.width
let maxHeight=this.controlProp.commProp.height
if (this.controlProp.textProp && this.controlProp.textProp.padding) {
maxWidth=maxWidth - this.controlProp.textProp.padding * 2
maxHeight=maxHeight - this.controlProp.textProp.padding * 2
}
return {
// 'max-width': maxWidth+ 'px',
// 'max-height': maxHeight+ 'px',
width: '100%',
height: '100%',
'box-sizing': 'content-box',
background: 'transparent',
'color': this.controlProp.textProp ? this.controlProp.textProp.fontcolor : '',
'font-size': this.controlProp.textProp ? this.controlProp.textProp.fontsize + 'px' : '',
'text-align': this.controlProp.textProp ? this.controlProp.textProp.horizonalign : '',
'line-height': maxHeight + 'px',
'vertical-align': this.controlProp.textProp ? this.controlProp.textProp.verticalalign : '',
'font-family': this.controlProp.textProp ? this.controlProp.textProp.fontfamily : '',
'font-weight': this.controlProp.textProp ? (this.controlProp.textProp.fontweight ? 600 : 500) : '',
'font-style': this.controlProp.textProp ? (this.controlProp.textProp.fontitalic ? 'italic' : 'normal') : ''
}
}
},
created() {
},
mounted() {
},
methods: {
initImports() {
return {
}
},
initProp() { //初始化狀態(tài) (基礎(chǔ)屬性 特殊屬性 文本屬性)
return {
commProp: { // 基礎(chǔ)屬性
width: 80,
height: 30,
borderwidth: 0,
backgroundColor: 'linear-gradient(90deg, #03a9f4, #00FFFF)',
borderradius:5
},
spProp:{ // 特殊屬性
},
textProp: { // 文本屬性
text: 'Button',
fontsize: 12,
fontcolor: 'black',
horizonalign: 'center',
verticalalign: 'middle',
padding: 0,
margin: 0
},
spPropSetting: [ // 特殊屬性 textinput/numberinput/switch/select/colorPicker/codeInput/dateInput/imgSelect/setup
]
}
}
}
}
這里需要注意:
initProp():方法中實(shí)現(xiàn)對(duì)組件的 基礎(chǔ)屬性 文本屬性 特殊屬性的初始化配置
更多屬性配置參考:http://krmes.com:8000/md/design/#%E7%BB%84%E4%BB%B6%E5%9F%BA%E7%A1%80%E5%B1%9E%E6%80%A7
點(diǎn)擊保存這樣我們?cè)O(shè)計(jì)的組件就顯示出來(lái)了!是不是很簡(jiǎn)單。
這樣在我們的web組態(tài)中就可以使用我們自定義的組件了![大笑][大笑][大笑]
*請(qǐng)認(rèn)真填寫(xiě)需求信息,我們會(huì)在24小時(shí)內(nèi)與您取得聯(lián)系。