整合營(yíng)銷服務(wù)商

          電腦端+手機(jī)端+微信端=數(shù)據(jù)同步管理

          免費(fèi)咨詢熱線:

          css 漸變跟隨鼠標(biāo)光標(biāo)按鈕動(dòng)畫(huà)

          css 漸變跟隨鼠標(biāo)光標(biāo)按鈕動(dòng)畫(huà)

          何使用css實(shí)現(xiàn)漸變跟隨鼠標(biāo)光標(biāo)的懸停效果。如下圖:

          實(shí)現(xiàn)思路:

          1. 聲明 --x 和- -y 兩個(gè) CSS 變量,用于跟蹤鼠標(biāo)在按鈕上的位置。
          2. 聲明一個(gè) --size 的 CSS 變量,用于修改背景漸變的尺寸大小。
          3. 使用 background: radial-gradient(circle closest-side, pink, transparent) 創(chuàng)建按鈕的徑向漸變背景效果。
          4. 使用document.querySelector()和EventTarget.addEventListener()給按鈕綁定'mousemove'事件。
          5. 使用element.getBoundingClientRect()和CSSStyleDeclaration.setProperty() 更新 --x 和--y 變量的值。

          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)中就可以使用我們自定義的組件了![大笑][大笑][大笑]


          主站蜘蛛池模板: 精品国产一区在线观看| 亚洲AV无码一区二区乱孑伦AS| 国产一区二区三区日韩精品| 亚洲欧美成人一区二区三区| 亚洲国产高清在线精品一区| 国产亚洲福利精品一区| 国产日韩一区二区三区在线观看 | 91午夜精品亚洲一区二区三区| 久久精品国产一区二区三| 99久久精品国产一区二区成人| 亚洲伦理一区二区| 成人毛片无码一区二区| 国产美女在线一区二区三区| 一区二区三区精品| 成人精品一区二区户外勾搭野战| 日本一区频道在线视频| 无码AV一区二区三区无码| 亚洲色婷婷一区二区三区| 国产日韩一区二区三区在线播放| 无码人妻一区二区三区兔费| 一区二区三区无码高清视频| 无码AV天堂一区二区三区| 精品久久久久久中文字幕一区| 国产精品成人国产乱一区| 精品国产一区二区三区不卡| 韩国精品一区视频在线播放| 久久久久人妻一区精品| 国产自产对白一区| 日韩免费一区二区三区在线| 一区二区三区亚洲视频| 亚洲国产综合无码一区| 国产一区二区三区不卡AV| 天码av无码一区二区三区四区 | 无码av中文一区二区三区桃花岛 | 麻豆一区二区99久久久久| 无码中文字幕人妻在线一区二区三区 | 久久人妻内射无码一区三区| 国产一区二区三区小向美奈子| 无码AV天堂一区二区三区| 国产成人无码一区二区三区在线| 亚洲午夜一区二区三区|