运行 不同的悬停模式
Run different patterns on hover
每次我将鼠标悬停在 div(svg) 上时,我都试图生成一个随机模式。
到目前为止,这是我的代码:
var items = ["#pattern-rect", "#pattern-circle", "#pattern-triangle","#pattern-star"];
$("div").hover(function(){
$("g").css({"visibility": "visible"});
var item = Math.floor(Math.random()*items.length);
$("g").css({"fill": "url(items[item])"});
}, function(){
$("g").css({"visibility": "hidden"});
});
$("g").css({"visibility": "hidden"});
$("g").css({"fill": "url(items[item])"}); This line is not working.
$("g").css({"fill": "url(items[item])"});
需要像这样:
$("g").css({"fill": "url(" + items[item] + ")"});
每次我将鼠标悬停在 div(svg) 上时,我都试图生成一个随机模式。
到目前为止,这是我的代码:
var items = ["#pattern-rect", "#pattern-circle", "#pattern-triangle","#pattern-star"];
$("div").hover(function(){
$("g").css({"visibility": "visible"});
var item = Math.floor(Math.random()*items.length);
$("g").css({"fill": "url(items[item])"});
}, function(){
$("g").css({"visibility": "hidden"});
});
$("g").css({"visibility": "hidden"});
$("g").css({"fill": "url(items[item])"}); This line is not working.
$("g").css({"fill": "url(items[item])"});
需要像这样:
$("g").css({"fill": "url(" + items[item] + ")"});