通过单击轮播Sharepoint 2010中的超链接来隐藏/显示Web部件

时间:2013-09-20 19:50:26

标签: jquery sharepoint web-parts

我正在尝试使用带有jQuery的标准轮播来隐藏或显示页面上的某些webpart区域。我有一个类添加到< li>第1部分,第2部分等,并且当您单击Section1等时,它会打开WebPartWPQ5。

有人能指出我正确的方向吗?

这就是我所拥有的:

<script type="text/javascript">

$(document).ready(function () {
    $('#MSOZoneCell_WebPartWPQ5').hide(); 

       $(".Section1").click(function(){
      $('#MSOZoneCell_WebPartWPQ5').toggle(); 
    });
  });
});
</script>

每个li都会在其下面打开一个最初隐藏的Web部件。

 <ul id="jtabs" class="jtabs"> 
 <li class="ShowSection1"><a href="#">Budget</a></li> 
 <li class="ShowSection2"><a href="#">Compensation</a></li> 
 </ul> 

有5个jTabs应该打开一个Web部件并关闭任何打开时单击的部分

 $(document).ready(function () { 
     $('#MSOZoneCell_WebPartWPQ5').hide();       
     $('#MSOZoneCell_WebPartWPQ6').hide(); 
         $("ul").on('click', 'li.ShowSection1', function(){     
         $('#MSOZoneCell_WebPartWPQ6').toggle(); }); 

         $("ul").on('click', 'li.ShowSection2', function(){    
         $('#MSOZoneCell_WebPartWPQ5').toggle(); 
   }); 
});

以下是Web部件代码的示例。我认为可以使用Web部件ID,因为它始终是唯一的ID。

     <WebPartPages:ContentEditorWebPart runat="server" __MarkupType="xmlmarkup" WebPart="true" __WebPartId="{D0ADB7E7-8348-4604-96BA-6B22745C057F}" >
   <WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
   <Title>Content Editor</Title>
     <FrameType>None</FrameType>
     <Description>Allows authors to enter rich text content.</Description>
     <IsIncluded>true</IsIncluded>
     <PartOrder>8</PartOrder>
     <FrameState>Normal</FrameState>
     <Height />
     <Width />
     <AllowRemove>true</AllowRemove>
     <AllowZoneChange>true</AllowZoneChange>
     <AllowMinimize>true</AllowMinimize>
     <AllowConnect>true</AllowConnect>
     <AllowEdit>true</AllowEdit>
     <AllowHide>true</AllowHide>
     <IsVisible>true</IsVisible>
     <DetailLink />
     <HelpLink />
     <HelpMode>Modeless</HelpMode>
     <Dir>Default</Dir>
     <PartImageSmall />
     <MissingAssembly>Cannot import this Web Part.</MissingAssembly>
     <PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge>
     <IsIncludedFilter />
     <ExportControlledProperties>true</ExportControlledProperties>
     <ConnectionID>00000000-0000-0000-0000-000000000000</ConnectionID>
     <ID>g_7ac31086_17de_44c1_9a0b_44a01f67a452</ID>
     <ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">/sites/WSS001905/SiteAssets/Carousel/carousel.txt</ContentLink>
     <Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
     <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
   </WebPart>
   </WebPartPages:ContentEditorWebPart>

这是完整的轮播文件:

<head>
<link rel="stylesheet" href="../SiteAssets/Carousel/core.css" type="text/css" media="screen">
<link rel="stylesheet" href="../SiteAssets/Carousel/jslideshow.css" type="text/css" media="screen">
<script type="text/javascript" src="../SiteAssets/Libraries/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="../SiteAssets/Libraries/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="../SiteAssets/Libraries/jslideshow-1.0.0.js"></script>
<style type="text/css">
body{ margin: 0px;}
h1{font-size: 24px; margin-bottom: 20px;}
p{font-size: 14px;}
/* clean gray
*******************************************************************************/
button.clean-gray {
  background-color: #eeeeee;
  background-image: -webkit-gradient(linear, left top, left bottom, from(#eeeeee), to(#cccccc));
  /* Saf4+, Chrome */
  background-image: -webkit-linear-gradient(top, #eeeeee, #cccccc);
  background-image: -moz-linear-gradient(top, #eeeeee, #cccccc);
  background-image: -ms-linear-gradient(top, #eeeeee, #cccccc);
  background-image: -o-linear-gradient(top, #eeeeee, #cccccc);
  background-image: linear-gradient(top, #eeeeee, #cccccc);
  border: 1px solid #ccc;
  border-bottom: 1px solid #bbb;
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  -ms-border-radius: 3px;
  -o-border-radius: 3px;
  border-radius: 3px;
  color: #333;
  font: bold 11px "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Geneva, Verdana, sans-serif;
  line-height: 1;
  padding: 8px 0;
  text-align: center;
  text-shadow: 0 1px 0 #eee;
  width: 150px; }
  button.clean-gray:hover {
    background-color: #dddddd;
    background-image: -webkit-gradient(linear, left top, left bottom, from(#dddddd), to(#bbbbbb));
    /* Saf4+, Chrome */
    background-image: -webkit-linear-gradient(top, #dddddd, #bbbbbb);
    background-image: -moz-linear-gradient(top, #dddddd, #bbbbbb);
    background-image: -ms-linear-gradient(top, #dddddd, #bbbbbb);
    background-image: -o-linear-gradient(top, #dddddd, #bbbbbb);
    background-image: linear-gradient(top, #dddddd, #bbbbbb);
    border: 1px solid #bbb;
    border-bottom: 1px solid #999;
    cursor: pointer;
    text-shadow: 0 1px 0 #ddd; }
  button.clean-gray:active {
    border: 1px solid #aaa;
    border-bottom: 1px solid #888;
    -webkit-box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
    -moz-box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
    -ms-box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
    -o-box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
    box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee; }
    .controls{
    border: 1px solid #d8d8d8; margin-top: 10px; padding: 10px;
    width: 604px;
    }
    .controls h2{
    font-size: 14px;
    font-weight: bold;
    margin-bottom: 5px;
    }
    .container{
    border: 1px solid #dddddd;
    width: 624px; margin: 0 auto;
    padding: 0px;
    background: #f7f7f7;
    z-index:-1;
    }
    .footer{
    padding: 10px 0 0;
    text-align: right;
    font-size: 11px;
    }
    .download{
    text-align: center;
    padding: 10px 0;
    }
    .cc{
    text-align: center;
    padding: 10px 0;
    border: solid #d8d8d8;
    border-width: 1px 0;
    }
    </style>
</head>

<body>

<div class="container">
    <div class="jslideshow">
    <ul class="jslides">
        <li>
            <div class="carousel-image"><img src="../SiteAssets/Carousel/budget.JPG" width="440" height="300" alt="Budget Image"></div>

            <div class="carousel-description">
                <h2 class="ShowSection1"><a  href="#">Budget</a></h2>&nbsp; Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur in massa ipsum. <a href="#">&raquo; Find out more</a>
            </div>
        </li>

        <li>
            <div class="carousel-image"><img src="../SiteAssets/Carousel/comp.JPG" width="440" height="300" alt="Budget Image"></div>

            <div class="carousel-description">
                <h2><a href="#">Compensation</a></h2>&nbsp; Fusce fringilla nibh ut nibh sodales vehicula. Sed metus nunc, mattis non fermentum quis, viverra non est. <a href="#">&raquo; Find out more</a>
            </div>
        </li>

        <li>
            <div class="carousel-image"><img src="../SiteAssets/Carousel/expenses.JPG" width="440" height="300" alt="JQuery Carousel Example Image 3"></div>

            <div class="carousel-description">
                <h2><a href="#">Expenses</a></h2>&nbsp; Sed lorem massa, laoreet sed viverra eu, ultrices sit amet libero. Curabitur lorem dolor, adipiscing et venenatis a, pharetra ac nisi. Nunc laoreet posuere faucibus. <a href="#">&raquo; Find out more</a>
            </div>
        </li>

        <li>
            <div class="carousel-image"><img src="../SiteAssets/Carousel/FinResults.JPG" width="440" height="300" alt="JQuery Carousel Example Image 4"></div>

            <div class="carousel-description">
                <h2><a href="#">Results</a></h2>&nbsp; Phasellus nec nunc est. Cras elit arcu, malesuada nec venenatis ac, sollicitudin in magna. <a href="#">&raquo; Find out more</a>
            </div>
        </li>

        <li>
            <div class="carousel-image"><img src="../SiteAssets/Carousel/Misc.JPG" width="440" height="300" alt="JQuery Carousel Example Image 5"></div>

            <div class="carousel-description">
                <h2><a href="#">Miscellaneous</a></h2>&nbsp; Quisque sit amet tortor eu tellus suscipit pretium. Nunc dolor mauris, sagittis ut laoreet non, vulputate ut sapien. <a href="#">&raquo; Find out more</a>
            </div>
        </li>
    </ul>

    <ul id="jtabs" class="jtabs">

        <li class="ShowSection1"><a href="#">Budget</a></li>

        <li class="ShowSection2"><a href="#">Compensation</a></li>

        <li class="ShowSection3"><a href="#">Expenses</a></li>

        <li class="ShowSection4"><a href="#">Results</a></li>

        <li class="ShowSection5"><a href="#">Miscellaneous</a></li>

    </ul>
</div><script type="text/javascript">
(function($) {
    $(document).ready(function() { //Standand variables
        $( "#button" ).click(function() {
            $('.jslideshow').jslideshow('updateSlideshow', {
            'effectType' : $( "#effectTypes" ).val(),
            'interval' : $( "#intervalSpeed" ).val(),
            'animationspeed' : $( "#animationSpeed" ).val()
            //'slidedown': "element.slideDown(plugin.settings.animationspeed, easing);"
         }); // calls the init method
    return false;
    });
    });
    })(jQuery);

</script>
<div class="controls" style="display:none">
<h2>Slideshow Controls</h2>
<label for="effectTypes">Effect Type</label>
<select name="effectTypes" id="effectTypes">
    <option value="core_fadein">
        Fade In (Jquery Core)
    </option>

    <option value="core_show">
        Show (Jquery Core)
    </option>

    <option value="core_slidedown">
        Slide Down (Jquery Core)
    </option>

    <option value="jqueryui_blind">
        Blind (Jquery UI)
    </option>

    <option value="jqueryui_clip">
        Clip (Jquery UI)
    </option>

    <option value="jqueryui_drop">
        Drop (Jquery UI)
    </option>

    <option value="jqueryui_fade">
        Fade (Jquery UI)
    </option>

    <option value="jqueryui_fold">
        Fold (Jquery UI)
    </option>

    <option value="jqueryui_puff">
        Puff (Jquery UI)
    </option>

    <option value="jqueryui_slide">
        Slide (Jquery UI)
    </option>

    <option value="custom_animate_1">
        Custom Animation (Jquery UI)
    </option>

</select> 
<label for="intervalSpeed">Interval Speed</label>
<select name="intervalSpeed" id="intervalSpeed">
    <option value="500">
        500ms
    </option>

    <option value="600">
        600ms
    </option>

    <option value="700">
        700ms
    </option>

    <option value="800">
        800ms
    </option>

    <option value="900">
        900ms
    </option>

    <option value="1000">
        1000ms
    </option>
    <option value="1500">
        1500ms
    </option>
    <option value="2000">
        2000ms
    </option>
    <option value="2500">
        2500ms
    </option>
    <option value="3000">
        3000ms
    </option>
</select>
<label for="animationSpeed">Animation Speed</label>
    <select name="animationSpeed" id="animationSpeed">
    <option value="200">
        200ms
    </option>

    <option value="300">
        300ms
    </option>

    <option value="400">
        400ms
    </option>

    <option value="500">
        500ms
    </option>

    <option value="600">
        600ms
    </option>

    <option value="700">
        700ms
    </option>

    <option value="800">
        800ms
    </option>

    <option value="900">
        900ms
    </option>

    <option value="1000">
        1000ms
    </option>
    <option value="1500">
        1500ms
    </option>
    <option value="2000">
        2000ms
    </option>
    <option value="2500">
        2500ms
    </option>
    <option value="3000">
        3000ms
    </option>
</select>
<div style="text-align: center; margin-top: 10px;">
<button href="#" id="button" class="clean-gray">Run Effect</button>
</div>
<script type="text/javascript">
jQuery.noConflict();
(function($) {
$(function() {
    $(document).ready(function() { //Standand variables

$('.jslideshow').jslideshow({
    'interval' : '4000',
    'animationspeed' : '1000',
    'effectType' : 'jqueryui_slide'
}); // calls the init method


});
});
})(jQuery);
</script>
</div>
</div>
<br/>
<hr>
</body>

您提供的代码会更改图像,但不会隐藏或显示Web部件。这里是完整的旋转木马,如果需要,可以通过scahles并打开链接,但它需要在它下面的页面上显示web部分。我感谢你迄今给予的所有帮助,但仍然没有。

1 个答案:

答案 0 :(得分:0)

你有一个额外的`});'在你的代码中。此外,如果您希望能够单击任何部分,请确保使您的课程更通用。如你所见,看起来你只想要点击第1部分来显示“#MSOZoneCell_WebPartWPQ5”。

这样的事情怎么样:

<强> HTML

<ul>
  <li class='section'>Section1</li>
  <li class='section'>Section2</li>
</ul>

<强> JS

$(document).ready(function () {
  $('#MSOZoneCell_WebPartWPQ5').hide(); 

  $("ul").on('click', 'li.section', function(){
    $('#MSOZoneCell_WebPartWPQ5').toggle(); 
  });
});

我将课程“部分”放在每个li上,以防它们包含其他li

修改 在看到呈现的HTML的图像后,以下内容应该有效。我已经包含了一个示例jsbin:http://jsbin.com/oBEgEpe/1/edit

$(document).ready(function() {
  var slides = $('.jslides li');

  // Hide all but the first
  $(slides).hide();
  $(slides).eq(0).show();

  $('#jtabs').on('click', 'li a', function(e) {
    e.preventDefault();
    var slide_number = $(this).closest('li').index();
    $(slides).hide();
    $(slides).eq(slide_number).show();
  });
});