4
我在屏幕上创建了一个矩形,当鼠标悬停时,我想在矩形上出现一些按钮。但我无法处理这项工作。我的代码如下。我不明白为什么如何将鼠标悬停在JavaScript中的矩形上?
这个。$('。control')。removeClass('hide');
此行不起作用。它也不会给出任何错误。
$(this.rect).html(................ ........ css({position:'absolute',padding : '10px的'});
我不能也明白我的这部分代码(堆栈不允许的div我不知道为什么)谢谢
var KineticModel = Backbone.Model.extend({
myRect: null,
createRect : function() {
alert("rectangle created.");
var rect=new Kinetic.Rect({
x: 50,
y: 50,
width: 150,
height: 150,
fill: 'green',
stroke: 'black',
strokeWidth: 1,
offset: [0, 0],
draggable: true,
});
rect.on("mouseover",function(){
alert("Hoover : ");
$('.control').removeClass('hide');
});
rect.on("mouseout",function(){
alert("Out : ");
});
rect.on("mousedown",function(){
alert("Down : ");
});
rect.on("mouseup",function(){
alert("Up : ");
});
return rect;
}
});
var KineticView = Backbone.View.extend({
tagName: 'span',
stage: null,
layer: null,
initialize: function (options) {
model: options.model;
el: options.el;
this.layer = new Kinetic.Layer();
this.stage = new Kinetic.Stage({ container: this.el, width: 1000, height: 500 });
this.stage.add(this.layer);
},
events: {
'click': 'spanClicked'
},
render: function() {
var rect = this.model.createRect();
$(this.rect).html('<div class="shape"/>'
+ '<div class="control delete hide"/>'
+ '<div class="control change-color hide"/>'
+ '<div class="control resize hide"/>'
+ '<div class="control rotate hide"/>').css({ position: 'absolute', padding: '10px' });
this.layer.add(rect);
this.stage.add(this.layer);
alert("render");
return this;
},
spanClicked: function() {
}
});
var kModel = new KineticModel({});
var kView = new KineticView({ el: '#container', model: kModel });
$('#shapetest').click(function() {
kView.render();
});
我试过了,没有用。 – nyrs91 2013-03-20 17:10:03
以下是整个代码的链接:http://jsfiddle.net/Pwxe3/ – user1422167 2013-03-20 17:17:49
对不起,我无法帮助您使用JSfiddle,您在JSfiddle中的代码使用http://d3lp1msu2r81bx.cloudfront.net/kjs /js/lib/kinetic-v4.3.3.min.js,这是在我的国家过滤,所以它不正确加载。但是我可以告诉你使用'$'而不是'this。$' – 2013-03-20 17:46:28