3

There are two circles for each of the four columns on the page. The inner circle is a mask for the viewable region of the spotlight when you rollover. The outer circle is a mask for the black overlay while we're still tracking the mouse.

The problem is they don't line up flush, there is that tiny space between them and it's driving me nuts. Any ideas of how to get rid of that spacing? I've been playing rounding the float values so that all of the positioning and sizing values are integer, but I haven't found the right combo yet.

Here is a link to the page: enter link description here I'm using a jQuery SVG plugin, but here is the code anyhow:

// Create an SVG for each .svg_mask
    $('.svg_mask').each(function (key) {
        $(this).css({
            'min-height' :cr*4.5,
            'min-width' : cr*4.5
        }).css({
            marginLeft: -$(this).width()/2,
            marginTop: -$(this).height()/2
        });

        $(this).svg();            
        var tw = $(this).outerWidth();
        var th = $(this).outerHeight();

    // circle mask
        var cm = Math.round(cr*3.14*1.25); // obsolete?
        var rx = tw/2-cm/2; // position from left rect edge
        var cx = tw/2; // position from left center 
        var cri = cr*1.2; //inner circle mask radius
        var cro = tw/2; // out circle mask radius

        var px = $(this).offset().left; // position for page
        var py = $(this).offset().top; // position for page
        this.pcx = px + cx; // relative pos center
        this.pcy = py + cx; // relative pos center

        $('svg', this).attr('viewBox', '0 0 '+tw+' '+th);
        var svg = $(this).svg('get');
        var defs = svg.defs();
        var filter = svg.filter(defs, 'blur'+key, 0, 0, tw, th, 
            {filterUnits: 'userSpaceOnUse'}); 
        svg.filters.gaussianBlur(filter, 'blur'+key, 
            'SourceAlpha', 10); 

    // Our spotlight & rect
        var circle_mask = svg.mask(defs, 'circle_mask'+key, 0, 0, tw, th, 
            {maskUnits: 'userSpaceOnUse'});

        svg.circle(circle_mask, cx, cx, cro,
            {strokeWidth: 0, fill:'white', fillOpacity: 0.8, strokeWidth: 0});

        this.circle = svg.circle(circle_mask, 0, 0, cri,
            {strokeWidth: 0, fill: 'black', fillOpacity: 1, filter: 'url(#blur'+key+')'});

    // Draw this rect
        svg.circle(cx, cx, cro,
            {strokeWidth: 0, mask: 'url(#circle_mask'+key+')', opacity: 1.0});

    // mask this region off to background svg
        svg.circle(window.mask, this.pcx, this.pcy, cro, 
            {strokeWidth: 0, fill: 'black'});
    });

Any help is appreciated.

Update

I haven't found a solution to seamlessly mask off a circle and composite another circle to fit in the space, but the design has changed and I no longer NEED a solution for this particular project. It would be nice to understand how to achieve the effect though. The link now reflects the new design with a new problem...

curiouser
  • 919
  • 2
  • 12
  • 21
  • Did you fix it? I don't see any gaps (firefox 6) – James Aug 25 '11 at 21:32
  • The gaps are the fine red circles. Do you see them James? – curiouser Aug 25 '11 at 21:48
  • This question has been answered since at http://stackoverflow.com/questions/28034337/odd-spacing-between-svg-elements – Ruskin Nov 18 '16 at 10:03
  • Does this answer your question? [Odd spacing between SVG elements](https://stackoverflow.com/questions/28034337/odd-spacing-between-svg-elements) – dippas Jun 18 '20 at 00:44
  • @dippas yes, same as the selected answer. The space was likely a result of word-spacing between inline-block elements. – curiouser Jun 19 '20 at 13:37

3 Answers3

0

This is likely due to the whitespace between the elements being rendered.

There is a discussion about this at How to remove the space between inline-block elements?

For a simple demonstration and solution see http://codepen.io/elliz/pen/dOOrxO ... code copied below:

.defs-only {
  display:block; position: absolute; 
  height:0; width:0; margin: 0; padding: 0; 
  border: none; overflow: hidden;
}

.margins svg {
  margin-right: -4px;
}

.floats {
  overflow: auto; /*clearfix*/  
}

.floats svg {
  float: left;
}
<svg class="defs-only" xmlns="http://www.w3.org/2000/svg">
  <symbol id="square">
    <rect x="0" y="0" width="100" height="100" fill="currentColor" />
  </symbol>
</svg>


<h1>SVG gap issue demonstration</h1>
<p>This pen demonstrates the gap that can appear between inline svg elements</p>
<svg width="36" height="36" viewBox="0 0 36 36"><use xlink:href="#square" style="color: blue" /></svg>
<svg width="36" height="36" viewBox="0 0 36 36"><use xlink:href="#square" style="color: red" /></svg>
<svg width="36" height="36" viewBox="0 0 36 36"><use xlink:href="#square" style="color: green" /></svg>

<h2>Attempt 1: remove whitespace between elements</h2>
<p>On a hunch lets try to remove the space between the elements...</p>
<svg width="36" height="36" viewBox="0 0 36 36"><use xlink:href="#square" style="color: blue" /></svg><svg width="36" height="36" viewBox="0 0 36 36"><use xlink:href="#square" style="color: red" /></svg><svg width="36" height="36" viewBox="0 0 36 36"><use xlink:href="#square" style="color: green" /></svg><p>Ah ... so it is the same issue that used to plague &lt;li&gt; tags when you tried to create seamless horizontal menu items<p>
  
<h2>Attempt to remove whitespace using css</h2>

<h3>Using negative margins</h3>
<div class="margins">
<svg width="36" height="36" viewBox="0 0 36 36"><use xlink:href="#square" style="color: blue" /></svg>
<svg width="36" height="36" viewBox="0 0 36 36"><use xlink:href="#square" style="color: red" /></svg>
<svg width="36" height="36" viewBox="0 0 36 36"><use xlink:href="#square" style="color: green" /></svg>
</div>

<p>Exact size of negative margin will depend on font size</p>

<h3>Using floats</h3>
<div class="floats">
<svg width="36" height="36" viewBox="0 0 36 36"><use xlink:href="#square" style="color: blue" /></svg>
<svg width="36" height="36" viewBox="0 0 36 36"><use xlink:href="#square" style="color: red" /></svg>
<svg width="36" height="36" viewBox="0 0 36 36"><use xlink:href="#square" style="color: green" /></svg>
</div>

<p>If you want to avoid a hairline gap between elements when viewed in retina, you may need to combine the two techniques above: e.g. floats with 1px negative margin.</p>

<h2>Further Reading</h2>
<ul>
  <li><a href="https://css-tricks.com/fighting-the-space-between-inline-block-elements/">CSS Tricks article on space between li elements</a></li>
  <li><a href="https://stackoverflow.com/questions/5078239/how-to-remove-the-space-between-inline-block-elements">Stack Overflow question discussing issue</a></li>
</ul>
Community
  • 1
  • 1
Ruskin
  • 4,838
  • 3
  • 37
  • 54
  • 1
    While I didn't check that the original problem is solved by removing the whitespace, I do believe this is the correct answer! – curiouser Aug 02 '18 at 18:08
0

Is it possible that your positioning code does not allow for a stroke width somewhere? Maybe on the circle? Specify stroke-width:0? Simplify what you are trying to do. Sometimes too much haste far less pace.

Chasbeen
  • 1,470
  • 12
  • 16
0

I think Chasbeen is correct. See the parameters to svg.circle (I got this from jquery svg docs):

svg.circle(70, 220, 50, {fill: "red", stroke: "blue", strokeWidth: 5}); 

In your circles, set the strokeWidth to 0.

EDIT: After reviewing your code I can't find any reason for that gap. Here's the best cheat I could come up with (it's definitely not perfect).

// mask this region off to background svg
    svg.circle(window.mask, this.pcx, this.pcy, cro, 
       {stroke: '#E3E3E3', strokeWidth: 2, fill: 'black'});
});
James
  • 14,812
  • 2
  • 21
  • 36
  • Tell me if I'm missing something, but I updated the code above with the strokeWidth value and I don't see a change. – curiouser Aug 25 '11 at 22:38
  • No I don't think you're missing anything. I don't know enough about masks and filters to be able to notice any pitfalls you might have encountered. I did play around with your code a bit, I got the gaps less noticeable by cheating but could not entirely make them go away. – James Aug 26 '11 at 03:40