2017-02-08 52 views
1

我想操縱2 divs我的網頁上,基本上在1 div是隱伏 - 在這個例子中div "template_class" - 另一個div擴展填補了國內空白,但此刻「template_class"皮,但沒有任何反應到另一個div爲什麼jQuery用戶界面 - .toogleClass()不工作

jQuery的:

$(function() { 
    $(".toogle").on("click", function() { 
     $(".template_class").toggleClass("newClass", 1000); 
     $("#content-link2").toggleClass("newClass3", 1000); 
    }); 
    }); 

個CSS:

.toogle{ 
    padding:0px 0px 0px 0px; 
    text-align: center; 
    margin:0px; 
    width: 160px; 
    height:40px; 
    top: 100px; 
    background:#FF931E; 
    z-index:15; 
    border-radius: 5px 5px 0px 0px; 
    -moz-transform:rotate(-90deg); 
    -ms-transform:rotate(-90deg); 
    -o-transform:rotate(-90deg); 
    -webkit-transform:rotate(-90deg); 
    transform-origin: bottom right; 
    position: relative; 
    right: 0px; 
} 
.newClass3{ 
    margin-top: 50px; 
    width: 95%; 
    height: 89%; 
    border: 2px solid blue; 
    float: right; 
} 
.newClass{ 
    top:0%; 
    width: 0%; 
    height: 0%; 
} 

HTML:

<div class="container template_class "> 
    @foreach ($templates as $template) 
    <a class="content-link" href="{{ asset($template->file)}}"> 
     <img src="{{ asset($template->image)}}"/> 
     </a> @endforeach 

</div> 
    <div class="pace pace-inactive"> 
    <div class="pace-progress" data-progress-text="100%" data-progress="99" style="width: 100%;"> 
     <div class="pace-progress-inner"></div> 
    </div> 
    <div class="pace-activity"></div> 
</div> 
<div class="features form-group"> 
    <input class="form-control filestyle margin images" data-input="false" type="file" data-buttonText="Upload Logo" data-size="sm" data-badge="false" onchange="readURL(this);" /> 

    <script> 
    $(function() { 
    $(document).tooltip(); 
    }); 
    </script> 
    <button style="display: none" class="form-control margin btn btn-primary" id="showColor">Show Colors</button> 
    <button style="display: none" class="form-control margin btn btn-primary" id="hideColor">Hide Colors</button> 
    <input title="Choose a color and then click on any box" style="display: none" class="btn btn-default form-control margin" type="color" id="colorChoice"> 
    <a style="display: none" href="#" class="btn btn-default form-control margin" id="cp4">Background</a> 

    <button style="display: none" onclick="$('#fonts1').bfhfonts({font: 'Arial'})" id="fontsShow" class="btn btn-primary form-control margin">Load Fonts</button> 
    <button style="display: none" class="btn btn-primary form-control margin" id="fontsHide">Hide Fonts</button> 
    <select title="Choose a font and then click on any box" style="display: none" id="fonts1" class="form-control margin"></select> 

    <button style="display: none" onclick="$('#googlefonts1').bfhgooglefonts({font: 'Lato'})" id="googleShow" class="btn btn-primary form-control margin">Google fonts</button> 
    <button style="display: none" class="btn btn-primary form-control margin" id="googleHide">Hide Google</button> 
    <select title="Choose a font and then click on any box" style="display: none" id="googlefonts1" class="form-control margin"></select> 

    <button style="display: none" onclick="$('#fontsizes1').bfhfontsizes({fontsize: '12'})" id="sizeShow" class="btn btn-primary form-control margin">Load font size</button> 
    <button style="display: none" class="btn btn-primary form-control margin" id="sizeHide">Hide font size</button> 
    <select title="Choose a font size and then click on any box" style="display: none" id="fontsizes1" class="form-control margin"></select> 

    <button style="display: none" class="form-control margin btn btn-default" id="finishEdit">Done</button> 
    <button class="form-control margin btn btn-default" id="startEdit">Edit</button> 

    <input type="hidden" name="_token" value="{{ csrf_token() }}"> 
    <button onClick=" updateDatabase(this);" type="button" class="form-control margin btn btn-warning" id="getRequest">Save</button> 
</div> 
<div id="content-link2"> 
     <button class="form-control btn btn-success toogle" ></button> 
</div> 
+1

粘貼HTML代碼,請 –

+0

我已經貼我的html代碼 – Przemek

+0

是的,它是時間 – Przemek

回答

1

首先,我認爲你使用.togleClass()功能錯誤。在你的情況下,它等於.toggleClass("classname", true),它只能將該類添加到元素,而不是切換它(source)。

除此之外,我認爲你的CSS是一個點。最好這樣做

.newClass{ 
    display: none; 
} 

至於其他divs,他們應該自動上去。我不知道#content-link2的初始風格,所以澄清將幫助你爲什麼需要使它浮權等

+0

的div的更大視圖content-link2應該變寬,如果我沒有浮動它會結束因爲它位於template_class – Przemek

+0

@Przemek之後,但是如果您使用我的css隱藏了template_class,它將不會被渲染,並且不會阻止其他div按鈕被點擊後。你能做一個小提琴來複制你的問題嗎? –

+0

這是絕對好的,但如果我再次按下按鈕,template_class不會顯示自己 – Przemek