Search code examples
jqueryhtmlcssinvisible

Issue with P tag content covering a block level link


I've been going insane with this j-query slider I adapted from juliendecaudin's barousel plugin

I've put it all on jsfiddle:

http://jsfiddle.net/psFMs

The four navigation blocks are created by the jquery code (which is why I'm having this problem). So because I needed text over each blocks, I added some p tags to the code and then positioned them over each block. This meant that they covered the links, and consequently the hover effects stop.

I have tried multiple things I thought would make it work with what limited jquery knowledge I have (when you hover over the p tag, show the relevant background image at the correct width and height and positioned, for instance) But none have worked!

What I would love to know is how to make the text act as a link like the navigation blocks, but also, make it so that when you hover over the text, the background image hovers too. Alternatively if there's a way I could fuse the two together that would be swell!

The html bit where I added the p-tags is here (the jquery code automatically creates the html ul li elements:

<div class="barousel_nav">
<p class="abs abs1">Value Proposition Development</p>
<p class="abs abs2">Sales Engagement</p>
<p class="abs abs3">Customer Communications</p>
<p class="abs abs4">Insight-driven Lead Generation Campaigns</p>
</div>

If I could specifiy each nav ul li link then I should be able to create a workaround, but as it stands each li has nothing specific about it!


Solution

  • You can change some bits to put it to work as you'd expect:

    On the jquery.barousel.js file, look for this snippet:

    //build the navigation
    if (settings.navType == 1) {
        //items navigation type
            var strNavList = "<ul>";
    

    And change it, by adding a class (navigationMenu) to the ul:

    //build the navigation
    if (settings.navType == 1) {
        //items navigation type
            var strNavList = "<ul class='navigationMenu'>";
    

    On your page header, after you load all the libraries, add the snippet below:

    <script type="text/javascript">
        $(function () {
            // Look for all the spans which contains the class abs, and move them
            // to the li accordingly.
            $("span.abs").each(function (index, element) {
                var target = $("ul.navigationMenu li")[index];
                $(this).appendTo($(target).find("a"));
            });
        });
    </script>
    

    Change your CSS, by removing unused rules:

    .barousel {
        height:408px;
        margin-bottom:85px;
        position:relative;
        width:750px;
    }
    .barousel_wrap {
        float:right;
        height:408px;
        width:650px;
    }
    .barousel_image {
        background-image:url(http://oliverbanham.com/quantumSite/images/SLIDER/images/bgGrayGradient.jpg);
        background-position:initial initial;
        background-repeat:repeat no-repeat;
        height:306px;
        padding-left:10px;
        width:660px;
    }
    .barousel_image img {
        display:none;
        position:absolute;
    }
    .barousel_image img.default {
        display:block;
    }
    .barousel_image img.current {
        z-index:10;
    }
    .barousel_content {
        background-color:#6D4682;
        background-image:url(http://oliverbanham.com/quantumSite/images/SLIDER/images/largegrad_05.jpg);
        background-position:initial initial;
        background-repeat:repeat no-repeat;
        display:block;
        height:auto;
        margin:0;
        padding:5px 10px 0;
        width:650px;
    }
    .barousel_content div {
        display:none;
        margin-bottom:7px;
        width:650px;
    }
    .barousel_content div.default {
        display:block;
        height:auto;
        padding-bottom:7px !important;
    }
    .barousel_content p {
        color:white;
        font-size:12px;
        font-weight:normal;
        line-height:16px;
        margin-bottom:8px !important;
        top:0;
        z-index:50;
    }
    .barousel_content p.sliderH {
        font-weight:bold;
        margin-bottom:5px;
    }
    .barousel_nav {
        float:left;
        height:408px;
        width:100px;
        z-index:20;
    }
    /*.barousel_nav p.abs {
        cursor:pointer;
        display:inline-block;
        font-size:11px;
        left:5px;
        margin:0 auto;
        position:absolute;
        text-align:center;
        width:90px;
    }
    .barousel_nav p.abs1 {
        top:35px;
    }
    .barousel_nav p.abs2 {
        top:135px;
    }
    .barousel_nav p.abs3 {
        bottom:140px;
    }
    .barousel_nav p.abs4 {
        bottom:25px;
        left:5px;
    }*/
    .barousel_nav ul {
        float:right;
        margin:0;
        padding:0;
    }
    .barousel_nav li {
        float:left;
        /*font-size:0;
        line-height:0;*/
        list-style:none;
        padding-left:3px;
    }
    .barousel_nav li a {
        background-image:url(http://oliverbanham.com/quantumSite/images/SLIDER/images/BTN_01.jpg);
        display:block;
        /*font-size:0;*/
        height:102px;
        /*line-height:0;*/
        text-decoration:none;
        width:100px;
    }
    .barousel_nav li a:hover {
        background-image:url(http://oliverbanham.com/quantumSite/images/SLIDER/images/current_BTN_01.jpg);
    }
    .barousel_nav li a.current {
        background-image:url(http://oliverbanham.com/quantumSite/images/SLIDER/images/current_BTN_01.jpg);
    }
    

    And finally, slightly change your HTML:

    <span class="abs">Value Proposition Development</span>
    <span class="abs">Sales Engagement</span>
    <span class="abs">Customer Communications</span>
    <span class="abs">Insight-driven Lead Generation Campaigns</span>
    

    Working demo: http://jsfiddle.net/psFMs/2/

    Of course there are some CSS tweaks to be done and make it look nicer, but the essential is here.