I'm trying to implement a css animated toggle switch in a rails view but without succeeding.
I want when the switch is triggered to post an action to my rails controller.
Here is my code:
in my view:
<div class="onoffswitch">
<%= check_box 'onoffswitch', '0', id:"myonoffswitch", class: 'onoffswitch-checkbox'%>
<label class="onoffswitch-label" for="myonoffswitch">
<div class="onoffswitch-inner"></div>
<div class="onoffswitch-switch"></div>
</label>
</div>
when the switch is triggered i want it to do this post:
<%= link_to "switch",{controller: "static_pages", action: "local_switch"}, method: :post %>
and then i have the css based on 'http://proto.io/freebies/onoff/':
.onoffswitch {
position: relative; width: 50px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 50% solid #CCCCCC; border-radius: 22px;
}
.onoffswitch-inner {
width: 200%; margin-left: -100%;
-moz-transition: margin 0.2s ease-in 0s; -webkit-transition: margin 0.2s ease-in 0s;
-o-transition: margin 0.2s ease-in 0s; transition: margin 0.2s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
float: left; width: 50%; height: 5px; padding: 0; line-height: 5px;
font-size: 16px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "";
padding-left: 10px;
background-color: #3498DB; color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "";
padding-right: 10px;
background-color: #CCCCCC; color: #FFFFFF;
text-align: right;
}
.onoffswitch-switch {
width: 20px; margin: -7.5px;
background: #FFFFFF;
border: 2px solid #CCCCCC; border-radius: 22px;
position: absolute; top: 0; bottom: 0; right: 43px;
-moz-transition: all 0.2s ease-in 0s; -webkit-transition: all 0.2s ease-in 0s;
-o-transition: all 0.2s ease-in 0s; transition: all 0.2s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}
Thank you!
try this ajax code...
$("#myonoffswitch").change(function(){
if ($(this).is(":checked"))
{
$.ajax({
type : "POST",
url : "/static_pages/local_switch", # add your correct url
dataType: 'script',
data : { id:2 }, #u can pass any no of data
success : function(data){
}
});
}
else{
}
});
this ajax request will be sent when your checkbox is checked or toggle to ON
Related
I want to create a button that is hidden initially but then displays over an image when the image is hovered. I want the button to animate from the top of the image(initially hidden) to the middle(displayed on hover). Here is an example, scroll to the "latest from blog" section and hover the image.
The problems I'm having:
I want the button hidden completely when the image is not hovered. Setting the opacity to zero doesn't fully hide it and if the user hovers over the hidden button it twitches.
If the user hovers the image, the button animates down over the image like it should. I want it to animate back up and disappear when the user stops hovering.
I've used CSS filter and a transition to darken the image on hover. When the button animates down over the image on hover the image is still dark like it should be, but when the user hovers directly over the newly displayed button the image goes back to it's normal brightness. I want the image to stay dark (like in the example) when the user is directly over the button.
Here is my code. How can I make this button hover effect exactly like it is in the first example I showed?
You should really show us the code without react, as this would be a lot easier for everyone to check and debug. Regardless, I went to your source, and copied all the CSS used from the content given. It all activates when you hover over div.entry-image-attachment.
Pure CSS
#submit,
button,
.button,
input[type=submit] {
border: 0;
text-transform: uppercase;
cursor: pointer;
font-family: inherit;
font-weight: 400!important;
line-height: 1;
margin: 0;
position: relative;
text-decoration: none;
text-align: center;
display: inline-block;
padding-top: .9375em;
padding-right: 1.875em;
padding-bottom: 1em;
padding-left: 1.875em;
font-size: .875em;
background-color: #2ecc71;
border-color: #2ecc71;
transition: all .5s ease 0s;
-webkit-transition: all .5s ease 0s;
-moz-transition: all .5s ease 0s;
color: #fff;
-webkit-border-radius: 2px;
border-radius: 2px;
}
.text-center {
text-align: center!important;
}
.trans-button {
background-color: transparent!important;
font-weight: bolder;
border-width: 1px;
border-style: solid;
}
.entry-image {
position: relative;
margin: 10px 0 15px;
}
.nd-content {
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
-webkit-transition: all .5s ease;
transition: all .5s ease;
}
.nd-content_inner {
display: table;
width: 100%;
height: 100%;
}
.nd-content_inner1 {
display: table-cell;
width: 100%;
height: 100%;
vertical-align: middle;
}
.nd-title {
position: relative;
top: -150px;
opacity: 0;
margin: 0 0 30px;
-webkit-transition: all .3s ease .01s;
transition: all 1s ease .01s; /*Animation happens with this*/
}
.button.white.trans-button {
color: #fff;
}
.entry-image-attachment:hover .nd-title {
-webkit-transition: all .5s cubic-bezier(1, -.53, .405, 1.425) .01s;
transition: all .5s cubic-bezier(1, -.53, .405, 1.425) .01s;
}
.entry-image-attachment:hover .nd-icon,
.entry-image-attachment:hover .nd-content,
.entry-image-attachment:hover .nd-title {
opacity: 1;
top: 0;
}
.button.trans-button {
padding: 15px;
}
#submit.white,
button.white,
.button.white,
input[type=submit].white {
background-color: #fff;
border-color: #fff;
transition: all .5s ease 0s;
-webkit-transition: all .5s ease 0s;
-moz-transition: all .5s ease 0s;
color: #333;
-webkit-border-radius: 2px;
border-radius: 2px;
}
.entry-image-attachment:hover .nd-icon,
.entry-image-attachment:hover .nd-content,
.entry-image-attachment:hover .nd-title {
opacity: 1;
top: 0;
}
.entry-image-attachment:hover .nd-content {
background: rgba(0, 0, 0, .5);
}
<div class="entry-image">
<div class="entry-image-attachment" style="max-height:200px;overflow:hidden;">
<img src="http://rosette.leetheme.com/wp-content/uploads/2014/12/02.jpg" width="296" height="180" />
<div class="nd-content text-center">
<div class="nd-content_inner">
<div class="nd-content_inner1">
<div class="button trans-button white nd-title"><span>Read more</span></div>
</div>
</div>
</div>
</div>
</div>
I use custom check box styling for my application, the problem I'm currently facing is that the custom check box style is rendered and the normal bootstrap check box.
As you can guess the custom check box is not clickable, but showing up.
Here is an example for the html:
<div class="form-group">
<strong class="container_check version_2">Ebay Angebot?
<%= check_box_tag :ebay_offer, true, [] %>
<span class="checkmark"></span>
</strong>
</div>
This is what the console throws out:
<input type="checkbox" name="ebay_offer" id="ebay_offer" value="true" checked="checked">
The corresponding bootstrap class (not my custom checkmark):
input[type=checkbox], input[type=radio]
My custom checkmark class
/** CHECKMARKS */
.container_check {
display: block;
position: relative;
font-size: 14px;
font-size: 0.875rem;
padding-left: 30px;
line-height: 1.3;
margin-bottom: 10px;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none
}
.container_check input {
position: absolute;
opacity: 0;
cursor: pointer
}
.container_check input:checked~.checkmark {
background-color: #2FE7B1;
border: 1px solid transparent
}
.container_check .checkmark {
position: absolute;
top: 0;
left: 0;
height: 20px;
width: 20px;
border: 1px solid #d2d8dd;
background-color: #fff;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
-ms-border-radius: 3px;
border-radius: 3px;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-webkit-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out
}
.container_check .checkmark:after {
content: "";
position: absolute;
display: none;
left: 7px;
top: 3px;
width: 5px;
height: 10px;
border: solid white;
border-width: 0 2px 2px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg)
}
.container_check.version_2 {
padding: 6px 0 0 45px;
min-height: 30px
}
.container_check.version_2 .checkmark {
height: 30px;
width: 30px
}
.container_check.version_2 .checkmark:after {
left: 12px;
top: 8px;
width: 5px;
height: 10px
}
.container_check input:checked~.checkmark:after {
display: block
}
Quite often with this kind of thing the span needs to be within the field or within the label. You could try formats like these:
<%= check_box_tag :ebay_offer, true, [] do %>
<span class="checkmark"></span>
<% end %>
or
<%= label_tag :ebay_offer do %>
<%= check_box_tag :ebay_offer %>
Any desired label text <span class="checkmark"></span>
<% end %>
I have a select box that sits directly next to an input box, (see relevant snippet below).
Currently, two seperate transition animations play in order to display both boxes on hover.
I would like to only use a single transition to display both boxes on hover.
Is there a cleaner way to do this? Could different positioning properties help me? Thanks in advance!
html, body {
background-color: rgba(64, 124, 165, 1);
}
.quick-search-container {
cursor: pointer;
width: 350px;
vertical-align: top;
white-space: nowrap;
position: relative;
top: -5px;
float: left;
}
.quick-search-container input#search {
width: 20px;
height: 30px;
background: rgba(64, 124, 165, 1); /*replacement*/
border: none;
font-size: 10pt;
float: right;
color: #262626;
padding-right: 35px;
padding-left: 5px;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
color: #000;
-webkit-transition: width .55s ease, background-color .55s ease;
-moz-transition: width .55s ease, background-color .55s ease;
-ms-transition: width .55s ease, background-color .55s ease;
-o-transition: width .55s ease, background-color .55s ease;
transition: width .55s ease, background-color .55s ease;
}
.quick-search-container input#search {
color: #65737e;
border: none;
}
.quick-search-container .icon {
position: absolute;
vertical-align: text-top;
right: 0;
margin-right: 10px;
margin-top: 6px;
color: #333;
font-size: 18px;
}
.quick-search-container .selector {
float: right;
vertical-align: text-top;
margin-right: 10px;
margin-top: 6px;
color: #ffffff;
font-size: 18px;
}
.quick-search-container input#search:focus,
.quick-search-container input#search:active,
select#selector:active {
outline: none;
}
.quick-search-container:hover input#search {
outline: none;
width: 180px;
background: #fff;
}
.quick-search-container:hover select#selector {
outline: none;
width: 100px;
}
.quick-search-container:hover .icon {
color: rgba(64, 124, 165, 1); /*replacement*/
}
.quick-search-container .selector {
margin-right: 0px;
margin-top: 0px;
transition: width .22s ease, background-color .55s ease;
}
.quick-search-selector {
margin-right: 0px;
margin-top: 0px;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
border: none;
height: 30px;
width: 0px;
color: black;
transition: width .55s ease, background-color .55s ease;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<a class="quick-search-container">
<span class="icon">
<i (click)="initQuickSearch()" class="fa fa-search"></i>
</span>
<input type="search" id="search" placeholder="Search...">
<span class="selector">
<select class="quick-search-selector" id="selector">
<option>VIN</option>
<option>Make</option>
<option>Model</option>
<option>Cow</option>
</select>
</span>
</a>
Just wrap input and select boxes into a container and set animations on it, see the simplified demo by using flexbox below. You can adjust the style as needed.
jsFiddle
html {
background-color: rgba(64, 124, 165, 1);
}
.quick-search-container {
position: relative;
width: 250px;
display: flex;
justify-content: flex-end;
align-items: center;
border: 1px solid;
}
.input-select {
width: 0;
overflow: hidden;
transition: width 1s;
display: flex;
}
.quick-search-selector {
width: 30%;
height: 30px;
}
.quick-search-input {
width: 70%;
-webkit-appearance: none;
outline: 0;
height: 30px;
}
.quick-search-container:hover .input-select {
width: 100%;
}
.quick-search-button {
position: absolute;
right: 0;
top: 0;
bottom: 0;
font-size: 16px;
background: none;
border: 0;
outline: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<a class="quick-search-container">
<span class="input-select">
<select class="quick-search-selector" id="selector">
<option>VIN</option>
<option>Make</option>
<option>Model</option>
<option>Cow</option>
</select>
<input type="search" class="quick-search-input" placeholder="Search..." id="search">
</span>
<button class="quick-search-button">
<i class="fa fa-search"></i>
</button>
</a>
How to create transition effect like:
http://jsfiddle.net/mfn5nefb/6/
but for text input?
I tried replace h1 with input but it does not work.
You have to change the HTML structure to do the same with input because you can't use pseudo elements like :after on an input element (which is an auto closing element)
HTML
<div id="input">
<input type="text" value="CSS IS AWESOME" /><span></span>
</div>
CSS
#input {
color: #666;
position: relative;
display: inline-block;
}
span {
position: absolute;
left: 50%;
content: '';
height: 40px;
height: 5px;
background: #f00;
transition: all 0.5s linear;
width: 0;
bottom: -5px;
}
input:hover ~ span {
width: 200px;
margin-left: -105px;
}
See this fiddle
.input_container{
display: inline-block;
text-align: center;
}
.awsome_input{
padding: 5px 10px;
border: none;
background: transparent;
display: block;
}
.awsome_input_border{
display:inline-block;
width:0px;
height: 2px;
background: #FEC938;
position: relative;
top:-5px;
-webkit-transition: all ease-in-out .15s;
-o-transition: all ease-in-out .15s;
transition: all ease-in-out .15s;
}
.awsome_input:hover,
.awsome_input:active,
.awsome_input:focus{
outline: none;
}
.awsome_input:hover+.awsome_input_border,
.awsome_input:active+.awsome_input_border,
.awsome_input:focus+.awsome_input_border{
width:100%;
}
<div class="input_container">
<input type="text" class="awsome_input"
placeholder="What do you think?"/>
<span class="awsome_input_border"/>
</div>
I've customised my radio buttons with the help of this tutorial.
Now I'm trying to add text next to the radio buttons but I can't really figure it out with this structure I've got.
Any ideas?
HTML:
<fieldset>
<div class="radioButton">
<input type="radio" name="x" value="y" id="y" />
<label for="y"></label>
</div>
<div class="radioButton">
<input type="radio" name="x" value="z" id="z" />
<label for="z"></label>
</div>
</fieldset>
CSS:
input[type=radio] {
visibility: visible; }
.radioButton {
width: 22px;
height: 22px;
background: #dedede;
margin: 20px 0px;
border-radius: 100%;
position: relative; }
/* Create the radio button */
.radioButton label {
display: block;
width: 18px;
height: 18px;
border-radius: 100px;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
-ms-transition: all .5s ease;
transition: all .5s ease;
cursor: pointer;
position: absolute;
top: 2px;
left: 2px;
z-index: 1;
background: white; }
/* Radio button checked state */
.radioButton input[type=radio]:checked + label {
background: #77a942; }
/*
Try adding the text inside the label and using CSS to indent it
.radioButton label{
text-indent: 2em;
}
UPDATE
Here's a better implementation using CSS's :before pseudo-element
Demo fiddle
input[type=radio] {
visibility: visible;
}
.radioButton {
height: 22px;
margin: 20px 0px;
position: relative;
}
.radioButton label {
display: inline-block;
vertical-align: middle;
padding-left: 0.5em;
}
/* Create the radio button */
.radioButton label:before {
content:'';
display: inline-block;
width: 18px;
height: 18px;
border-radius: 50%;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
-ms-transition: all .5s ease;
transition: all .5s ease;
cursor: pointer;
position: absolute;
top: 2px;
left: 2px;
z-index: 1;
background: white;
border: solid 2px #ddd;
}
/* Radio button checked state */
.radioButton input[type=radio]:checked + label:before {
background: #77a942;
}
Add a div after the radioButton div with your text. This isn't optimal, because the control has highjacked the label, so you can't click on this text and have the control be clicked (unless you add javascript to do that), but it'll look right. http://jsfiddle.net/MdAEG/
<fieldset>
<div class="radioButton">
<input type="radio" name="x" value="y" id="y" />
<label for="y"></label>
</div>
<div class="radioLabel">Hi there</div>
<div class="radioButton">
<input type="radio" name="x" value="z" id="z" />
<label for="z"></label>
</div>
<div class="radioLabel">Howdy</div>
</fieldset>
input[type=radio] {
visibility: visible; }
.radioLabel {
float: left;
clear:right;
margin: 22px 5px;
}
.radioButton {
width: 22px;
height: 22px;
background: #dedede;
margin: 20px 0px;
border-radius: 100%;
position: relative;
float: left;
clear: left;
}
/* Create the radio button */
.radioButton label {
display: block;
width: 18px;
height: 18px;
border-radius: 100px;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
-ms-transition: all .5s ease;
transition: all .5s ease;
cursor: pointer;
position: absolute;
top: 2px;
left: 2px;
z-index: 1;
background: white; }
/* Radio button checked state */
.radioButton input[type=radio]:checked + label {
background: #77a942; }
Just add the following CSS
label{
padding-left: 23px;
}
Then add some text to your label
<label for="z">Label here</label>
JSFiddle - http://jsfiddle.net/z9Pb9/