【发布时间】:2015-01-10 20:16:45
【问题描述】:
我的灵感来自http://codepen.io/andreasstorm/pen/syvoL的这段代码sinppet
HTML -
<header>
<div id="range"></div>
<div id="currentVal">background-image: linear-gradient( <span id="spanVal">180</span>deg , <span style="color:#4ac1ff">#4ac1ff</span>, <span style="color:#795bb0">#795bb0</span> )</div>
</header>
<div class="gradient"></div>
CSS(手写笔)-
html
height 100%
body
background-color #292c2f
font-family monospace
overflow hidden
.gradient
height calc(100% - 70px)
background-image linear-gradient(180deg,#4ac1ff,#795bb0)
position absolute
width 100%
header
background #252525
height 70px
line-height 70px
#currentVal
color #424242
font-size 14px
font-weight 800
padding-left 240px
span
color #ccc
#range
width 180px
border 0
height 4px
background #424242
outline none
position absolute
left 30px
top 32px
.ui-slider-handle
position absolute
margin 0px 0 0 -7px
border-radius 100%
background white
border 0
height 14px
width 14px
outline none
cursor pointer
&:hover
&:focus
transform scale(1.1)
.ui-slider-range
background #4ac1ff
JavaScript (coffeeScript) -
$("#range").slider
range: "min"
max: 360
value: 180
slide: (e, ui) ->
$("#spanVal").html ui.value
bg = "linear-gradient(" + ui.value + "deg,#4ac1ff,#795bb0)"
$(".gradient").css "background-image", bg
以同样的方式,我试图在网页背景上实现它,尽管我并不精通 JavaScript。无论如何我们可以对鼠标移动实现相同的效果吗?我的意思是随着光标在屏幕上的位置改变渐变的程度。
任何帮助将不胜感激!
【问题讨论】:
-
你想把它应用到整个网页吗?
-
是的,无论如何都可以在 JavaScript 中执行此操作。将鼠标悬停事件添加到正文。 $('body').mouseover();并计算鼠标指针的位置。
-
为什么不直接看你的coffeescript编译成的js呢?
标签: javascript jquery html css canvas