2012-06-06 45 views
0

我使用的骨干和有以下几种观点:的jQuery的.css()的FF不工作,但确实在Chrome和Safari的工作

class GT.RunManager.Views.FloorplanView extends Backbone.View 
    className: 'floorplan-view' 

    events: 
    'click .violation-marker' : 'edit_location' 
    'click' : 'create_location' 

initialize: (@options) -> 
    @run = @options.run 
    @student = @options.student 
    @floorplan = @options.run.get('floorplan') 
    @locations = new GT.RunManager.Collections.Locations() 
    @locations.run = @options.run 
    @locations.on 'add', @set_marker 
    @locations.on 'reset', @load_markers 

@run.on 'remove_location', (location) => 
    location.destroy() if location 
    @load_markers() 

@locations.fetch data: { student_id: @student.id } 
@render() 

render: => 
    if @floorplan 
    @$el.css 'background-image', "url(data:image/png;base64,#{@floorplan.url})" 
    this  

create_location: (e) => 
    @locations.create x: e.offsetX - 10, y: e.offsetY - 10, student_id: @student.id, run_id: @run.id 

load_markers: => 
    @$el.find('i').remove() 
    @locations.each (location) => @set_marker(location, false) 

set_marker: (location, prompt = true) => 
    marker = new GT.RunManager.Views.ViolationMarker(location: location, x: location.get('x'), y: location.get('y')) 
    @$el.append marker.el 
    if prompt 
    @run.trigger 'violations:set', location 

class GT.RunManager.Views.ViolationMarker extends Backbone.View 
className: 'violation-marker' 

template: JST['app/templates/violation_marker'] 

initialize: (@options) -> 
    @x = @options.x 
    @y = @options.y 
    @location = @options.location 
    @render() 

render: => 
    @$el.html @template() 
    @$el.data 'location', @location 
    @$el.css 
    'top': @y 
    'left': @x 
    this 

这是从所谓的这个想法是在用户触摸它的屏幕上放置一个图标(在iPad上,用于实验)。它在Chrome和Safari中运行良好,但在Firefox中不起作用,其中图标位于父div的左上角。

任何想法?

编辑:这骨干视图风格与下面的CSS:

div.violation-marker { 
position: absolute; 
background-color: red; 
@include border-radius(6px); 
padding: 4px;} 

模板仅仅是(引导):

<i class="icon icon-fire icon-white"></i> 

和父格样式为:

.floorplan-view { 
position: relative; 
float: left; 
margin-left: 100px; 
width: 755px; 
height: 755px; }  
+0

其他CSS应用于'@ el'及其父元素? –

+0

这是唯一适用于@el的css。它有一个类的CSS'div.violation-marker { } \t \t position:absolute; \t \t background-color:red; \t \t @include border-radius(6px); \t \t padding:4px; \t}' – John

+0

父母呢?父母的位置是:亲戚吗? '.violation-marker'没有大小? –

回答

0

原来的问题是,Firefox不处理e.offsetX和e.offsetY。只要我改变了我捕捉位置的方式,一切正常。这里是抓住的x坐标的火狐防版本:

x = (ev.offsetX || ev.clientX - $(ev.target).offset().left)

感谢所有帮助。

相关问题