I have a link button with jQuery mobile.
I want to be able to set it to be constantly pressed or unpressed.
I tried this code for pressed:
$(this).css('background-color', '#e0e0e0');
and this code for unpressed:
$(this).css('background-color', '#f6f6f6');
But when hovering over the unpressed button it does not highlight anymore.
So I tried:
$(this).addClass('ui-button-active');
But the button gets a blue color and I want dark gray color.
Any suggestions?
In jQuery Mobile 1.4.2 CSS you can see that there are button styles for normal/hover/active states (for each theme), and an active style that changes the color of the button (to blue, in your case).
To simulate a "constantly pressed" button you have to add a class for each theme (a and b) based on the button :active class, and override background color:
.button-pressed-a { background-color: #e8e8e8 !important; }
.button-pressed-b { background-color: #404040 !important; }
Then, in your script, you can toggle the "pressed" state with:
$("#button").toggleClass('button-pressed-a');
Have you been to themeroller? There you can try out different styles.
Adding a Custom Theme
Another good way to customize a jQuery Mobile button is adding a custom theme.
<a data-role="button" data-theme="my-site">Button</a>
That will give you more control over the different elements and states of the button. For instance, you can target different states of the button in CSS by writing the code for the class associated with your custom theme name (they are automatically added to the button):
.ui-btn-up-my-site { /* your code here */ }
.ui-btn-hover-my-site { /* your code here */ }
.ui-btn-down-my-site { /* your code here */ }
Keep in mind that the default buttons are made out of borders, shadows, and of course the background gradient. In addition to this, there are other HTML elements inside the button that are automatically generated by the framework. Depending on what exactly you want to customize you might need to target other classes within the button (i.e. ui-icon, ui-btn-text, ui-btn-inner, etc).
Otherwise I could recommend you this site
http://appcropolis.com/blog/advanced-customization-jquery-mobile-buttons/
Related
When I click on an Angular UI Grid column's arrow icon to show the dropdown menu for that column, then click the arrow icon again to hide it, the menu "shoots" up in an animated fashion, which I find undesirable.
How can I disable this behavior?
The ngAnimate module is responsible for the animation. You can exclude that from the application. If any of your dependent js libraries require ngAnimate then this may not be possible.
var app = angular.module('app', ['ngTouch', 'ui.grid']);
Example without the ngAnimate
http://plnkr.co/edit/EEI8te66R2aa4H9UFTHX?p=preview
As described in this answer, there is a generic, non-UI-Grid-specific way of disabling animations for specific elements. Note that this doesn't affect only animations perpetrated by ngAnimate; rather, this disables all animations in general.
From the original answer:
Just add this to your CSS. It is best if it is the last rule:
.no-animate {
-webkit-transition: none !important;
transition: none !important;
}
then add no-animate to the class of element you want to disable.
Example:
<div class="no-animate"></div>
So, to disable animation of the grid's menus, do the following (using Sass, but you get the idea):
.ui-grid-menu-mid {
#extend .no-animate; // the .ng-animate class is as defined above
}
The only real downside that I can see with this method is that you can't selectively disable animations for column and/or grid menus, only for both at the same time.
I'm using Mobiscroll 2.0.3. The datepicker view gives ok button on the left and cancel button on the right. Can I exchange the position, like the cancel button on the left and set button on the right? Because I have ok/cancel buttons placed in the opposite way to Moviscroll on the site. Users would get confused if the button positions are different at each.
You should be able to do that just using CSS and overriding the styles. I did it for the scroll-wheel view but the idea is the same (also note that that this was for mobiscroll 1.5.3 so the the markup and classes may have changed)
/* overide stlyes for mobi date/time picker */
.dwb-c
{
float:left;
margin-bottom:12px;
}
.dwb-s
{
float:right;
margin-bottom:12px;
}
I know it's late but if someone try to google it, just try this https://docs.mobiscroll.com/jquery/datetime#opt-buttons
You can set an array of buttons to display and you can use string names if you wanna show default buttons. So if you wanna change direction just set buttons like this:
buttons: ["cancel", "set"]
I have three radio buttons which have the same theme in jquery. If I select one of them, the color of the button will change to the color specified in my .ui-btn-active class in the css. My radio buttons are named Can meet, not sure and Decline. I want my Decline radio button to have a different color than the two others when it is selected (the color red).
I'm using Jquery mobile and have customized the css for which colors I want to have on the different themes and I have changed the .ui-btn-active to .ui-btn-active-a and .ui-btn-active-b and made them with different values. I have tried to switch between the two ui-btn-active classes without no luck, and I have tried the addClass(..) and removeClass(..) without luck. I made a method in my jquery-mobile.js which look like this:
$.mobile.changeAction = function( activeBtn){
$.mobile.activeBtnClass = activeBtn;
}
where my activeBtn parameter will be a string to choose which activeBtnClass I want to have. I think the problem is that I have problems refreshing the activeBtnClass after overriding it, I have tried some refreshing methodes without no luck.
As long as the radio buttons have different colors when active I will be very thankful.
Following styles should do the trick:
.ui-radio:nth-child(1) .ui-icon-radio-on.ui-icon{
background-color:green;
}
.ui-radio:nth-child(2) .ui-icon-radio-on.ui-icon{
background-color:grey;
}
.ui-radio:nth-child(3) .ui-icon-radio-on.ui-icon{
background-color:red;
}
Sample jsfiddle.
To style Horizontally stacked select options:
.ui-radio:nth-child(1) .ui-radio-on span.ui-btn-inner{
background-color:green;
}
.ui-radio:nth-child(2) .ui-radio-on span.ui-btn-inner{
background-color:grey;
}
.ui-radio:nth-child(3) .ui-radio-on span.ui-btn-inner{
background-color:red;
}
Sample jsfiddle.
Why not just create custom themes for all of the states that you might want? You can have multiple custom themes, and only use them when you'd like. I have 7 themes in my CSS, and this way you can always incorporate them later if you'd like without having to do so much custom coding.
You can just apply the theme with the data-theme="f" (or other letter swatch) element attribute.
Here's jQuery ThemeRoller 1.1.1 http://jquerymobile.com/themeroller/index.php. If you're just making small changes to the theme, such as an active state, just copy the theme, and make the changes and save as a new swatch. You can go from A-Z :)
I have buttons in my web app using jQuery Mobile.
When clicked the buttons have the ui-focus class added which displays a blue halo around buttons. The class stays there until another spot on the page is clicked. This happens in firefox, not iPad. I would like that this halo is not displayed.
What must I do for that focus halo not to be displayed at all ?
You can override the default css instead of hacking up the source. Just make sure your css file is after the JQM one.
.ui-focus,
.ui-btn:focus {
-moz-box-shadow: none;
-webkit-box-shadow: none;
box-shadow: none ;
}
I have found that the best way to do this is to give focus back to the page after your buttons are clicked.
$('yourButtons').click(function(){
//Do some important stuff
// ....
$.mobile.activePage.focus();
});
Well thats easy, just open your xxx-mobile-theme.css file and find the class ui-focus
and remove the box-shadow property manually
None of the solutions worked for me as I had a custom submit button and used data-role="none" on the button. The :focus event still had the blue glow so this worked for me. I wrapped my form in a div called myform.
.myform button:focus {
outline: 0;
}
How do I change the <a data-role="button"> button's background to my image? Also how can I add my custom icons on top of a button at left side?
Give the link a class and use CSS to change the background image.
<a data-role="button" class="my-button">
...
.my-button {
background-image: url('images/my-button.png') !important;
}
I would say that the recommended way to customize a jQuery Mobile button is adding a custom theme.
<a data-role="button" data-theme="my-site">Button</a>
That will give you more control over the different elements and states of the button. For instance, you can target different states of the button in CSS by writing the code for the class associated with your custom theme name (they are automatically added to the button):
.ui-btn-up-my-site { /* your code here */ }
.ui-btn-hover-my-site { /* your code here */ }
.ui-btn-down-my-site { /* your code here */ }
Keep in mind that the default buttons are made out of borders, shadows, and of course the background gradient. There also additional HTML elements inside the button that are automatically generated by the framework. Depending on what exactly you want to customize you might need to target other classes within the button (ui-icon, ui-btn-text, ui-btn-inner, etc).
Here is a tutorial that explains how to do advanced customization of the jQuery Mobile buttons. The articles shows how to do some basic customization, how to reset the jQuery Mobile theme, and how to turn the default button into anything you want:
http://appcropolis.com/blog/advanced-customization-jquery-mobile-buttons/